diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2022-01-29 16:43:20 +0100 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2022-02-05 20:20:01 +0100 |
commit | fe14f880500cd842eadd581b7261538bb9646b7f (patch) | |
tree | 41b16ec9289fbfd0feae9b2661a000c18934247f | |
parent | b9b4cecf9bd5208269bd706965be8ceb215cdcaf (diff) | |
download | u-boot-fe14f880500cd842eadd581b7261538bb9646b7f.tar.gz u-boot-fe14f880500cd842eadd581b7261538bb9646b7f.tar.bz2 u-boot-fe14f880500cd842eadd581b7261538bb9646b7f.zip |
lib: fix snprintf() for UTF-16 strings
snprintf() must return the required buffer length.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
-rw-r--r-- | lib/vsprintf.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 69b2f6a1ad..fe06aa2d71 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -285,15 +285,25 @@ static __maybe_unused char *string16(char *buf, char *end, u16 *s, if (!(flags & LEFT)) for (; len < field_width; --field_width) ADDCH(buf, ' '); - for (i = 0; i < len && buf + utf16_utf8_strnlen(str, 1) <= end; ++i) { + if (buf < end) + *buf = 0; + for (i = 0; i < len; ++i) { + int slen = utf16_utf8_strnlen(str, 1); s32 s = utf16_get(&str); if (s < 0) s = '?'; - utf8_put(s, &buf); + if (buf + slen < end) { + utf8_put(s, &buf); + if (buf < end) + *buf = 0; + } else { + buf += slen; + } } for (; len < field_width; --field_width) ADDCH(buf, ' '); + return buf; } |