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

Alexandre Julliard julliard at winehq.org
Fri Nov 17 16:02:18 CST 2017


Module: wine
Branch: master
Commit: ee32799d61c03266f327ec3af9dc3309de7163ea
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ee32799d61c03266f327ec3af9dc3309de7163ea

Author: Martin Storsjo <martin at martin.st>
Date:   Fri Nov 17 12:39:39 2017 +0200

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: Martin Storsjo <martin at martin.st>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/wcs.c            |  4 ++++
 dlls/ucrtbase/tests/printf.c | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index 88f52e0..0c54800 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -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) {
diff --git a/dlls/ucrtbase/tests/printf.c b/dlls/ucrtbase/tests/printf.c
index 77fb560..0e38003 100644
--- a/dlls/ucrtbase/tests/printf.c
+++ b/dlls/ucrtbase/tests/printf.c
@@ -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,




More information about the wine-cvs mailing list