From 3812fd3006e4f039a4744784178b9ce9356a38f0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Jan 2011 12:41:03 +0100 Subject: [PATCH] libwine: Fix handling of null character in vsnprintfW for %c format. --- libs/wine/string.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/wine/string.c b/libs/wine/string.c index 6afb89967e3..8f85c632062 100644 --- a/libs/wine/string.c +++ b/libs/wine/string.c @@ -300,7 +300,7 @@ noconv: /* format a WCHAR string according to a printf format; helper for vsnprintfW */ -static int format_string( WCHAR *buffer, size_t len, const char *format, const WCHAR *str ) +static int format_string( WCHAR *buffer, size_t len, const char *format, const WCHAR *str, int str_len ) { size_t count = 0; int i, left_align = 0, width = 0, max = 0; @@ -316,13 +316,14 @@ static int format_string( WCHAR *buffer, size_t len, const char *format, const W while (isdigit(*format)) width = width * 10 + *format++ - '0'; + if (str_len == -1) str_len = strlenW( str ); if (*format == '.') { format++; while (isdigit(*format)) max = max * 10 + *format++ - '0'; - for (i = 0; i < max; i++) if (!str[i]) max = i; + if (max > str_len) max = str_len; } - else max = strlenW(str); + else max = str_len; if (*format == 'h' || *format == 'l') format++; @@ -425,7 +426,7 @@ int vsnprintfW(WCHAR *str, size_t len, const WCHAR *format, va_list valist) *fmta++ = 's'; *fmta = 0; - count = format_string( str, len - written, fmtbufa, wstr ? wstr : none ); + count = format_string( str, len - written, fmtbufa, wstr ? wstr : none, -1 ); if (count == -1) return -1; str += count; written += count; @@ -435,14 +436,13 @@ int vsnprintfW(WCHAR *str, size_t len, const WCHAR *format, va_list valist) case 'c': { - WCHAR wstr[2]; + WCHAR wstr; int count; - wstr[0] = va_arg(valist, int); - wstr[1] = 0; + wstr = va_arg(valist, int); *fmta++ = 's'; *fmta = 0; - count = format_string( str, len - written, fmtbufa, wstr ); + count = format_string( str, len - written, fmtbufa, &wstr, 1 ); if (count == -1) return -1; str += count; written += count;