Commit ee32799d authored by Martin Storsjo's avatar Martin Storsjo Committed by Alexandre Julliard

ucrtbase: Always return the full string length in __stdio_common_vs[w]printf for a NULL buffer.

If the target is a NULL buffer (with a zero length), we should always return the full size the format would have needed, even if UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR isn't specified. Signed-off-by: 's avatarMartin Storsjo <martin@martin.st> Signed-off-by: 's avatarPiotr Caban <piotr@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 29a0537d
......@@ -764,6 +764,8 @@ int CDECL MSVCRT__stdio_common_vsprintf( unsigned __int64 options, char *str, MS
&ctx, format, locale, options & UCRTBASE_PRINTF_MASK, arg_clbk_valist, NULL, &valist);
puts_clbk_str_a(&ctx, 1, &nullbyte);
if(!str)
return ret;
if(options & UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION)
return ret>len ? -1 : ret;
if(ret>=len) {
......@@ -1282,6 +1284,8 @@ int CDECL MSVCRT__stdio_common_vswprintf( unsigned __int64 options,
&ctx, format, locale, options & UCRTBASE_PRINTF_MASK, arg_clbk_valist, NULL, &valist);
puts_clbk_str_w(&ctx, 1, &nullbyte);
if(!str)
return ret;
if(options & UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION)
return ret>len ? -1 : ret;
if(ret>=len) {
......
......@@ -215,6 +215,10 @@ static void test_snprintf (void)
ok (vsprintf_wrapper (UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, NULL, 0, "abcd") == 4,
"Failure to snprintf to NULL\n");
ok (vsprintf_wrapper (UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, NULL, 0, "abcd") == 4,
"Failure to snprintf to NULL\n");
ok (vsprintf_wrapper (0, NULL, 0, "abcd") == 4,
"Failure to snprintf to NULL\n");
}
static int WINAPIV vswprintf_wrapper(unsigned __int64 options, wchar_t *str,
......@@ -289,6 +293,13 @@ static void test_swprintf (void)
ok (buffer[valid] == '\0',
"\"%s\": Missing null termination (ret %d) - is %d\n", narrow_fmt, n, buffer[valid]);
}
ok (vswprintf_wrapper (UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, NULL, 0, str_short) == 5,
"Failure to swprintf to NULL\n");
ok (vswprintf_wrapper (UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, NULL, 0, str_short) == 5,
"Failure to swprintf to NULL\n");
ok (vswprintf_wrapper (0, NULL, 0, str_short) == 5,
"Failure to swprintf to NULL\n");
}
static int WINAPIV vfprintf_wrapper(FILE *file,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment