summaryrefslogtreecommitdiff
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2018-08-31 21:31:29 +0200
committerAlexander Graf <agraf@suse.de>2018-09-23 21:55:29 +0200
commit31bd711cd03dde22484cf647b9abe498ae1b0c5f (patch)
treef83fb67555f930a3eb97c85715c7d397cb241eb0 /lib/vsprintf.c
parentf11a164b58860c3971e207a2e1cf1c033b9d0910 (diff)
lib: vsprintf: correct printing of Unicode strings
The width and precision of the printf() function refer to the number of characters not to the number of bytes printed. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 5abf734750..4213441fbf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -280,18 +280,13 @@ static char *string16(char *buf, char *end, u16 *s, int field_width,
int precision, int flags)
{
u16 *str = s ? s : L"<NULL>";
- int utf16_len = u16_strnlen(str, precision);
- u8 utf8[utf16_len * MAX_UTF8_PER_UTF16];
- int utf8_len, i;
-
- utf8_len = utf16_to_utf8(utf8, str, utf16_len) - utf8;
+ ssize_t len = utf16_strnlen(str, precision);
if (!(flags & LEFT))
- while (utf8_len < field_width--)
+ for (; len < field_width; --field_width)
ADDCH(buf, ' ');
- for (i = 0; i < utf8_len; ++i)
- ADDCH(buf, utf8[i]);
- while (utf8_len < field_width--)
+ utf16_utf8_strncpy(&buf, str, len);
+ for (; len < field_width; --field_width)
ADDCH(buf, ' ');
return buf;
}