mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 23:24:38 +00:00
lib: fix snprintf() for UTF-16 strings
snprintf() must return the required buffer length. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
parent
b9b4cecf9b
commit
fe14f88050
1 changed files with 12 additions and 2 deletions
|
@ -285,15 +285,25 @@ static __maybe_unused char *string16(char *buf, char *end, u16 *s,
|
||||||
if (!(flags & LEFT))
|
if (!(flags & LEFT))
|
||||||
for (; len < field_width; --field_width)
|
for (; len < field_width; --field_width)
|
||||||
ADDCH(buf, ' ');
|
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);
|
s32 s = utf16_get(&str);
|
||||||
|
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
s = '?';
|
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)
|
for (; len < field_width; --field_width)
|
||||||
ADDCH(buf, ' ');
|
ADDCH(buf, ' ');
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue