[crt]
authorChristoph von Wittich <christoph_vw@reactos.org>
Sun, 7 Sep 2014 10:34:17 +0000 (10:34 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Sun, 7 Sep 2014 10:34:17 +0000 (10:34 +0000)
fix behavior of _sxprintf when a NULL buffer is supplied
fixes ntdll:string winetest

svn path=/trunk/; revision=64056

reactos/lib/sdk/crt/printf/_sxprintf.c
reactos/lib/sdk/crt/printf/streamout.c

index 4666719..b2ba6dc 100644 (file)
@@ -57,12 +57,6 @@ _sxprintf(
     int result;
     FILE stream;
 
-    /* Check trivial case */
-    if ((buffer == NULL) && (count == 0) && (sizeOfBuffer == 0))
-    {
-        return 0;
-    }
-
 #if IS_SECAPI
     /* Validate parameters */
     if (MSVCRT_CHECK_PMT(((buffer == NULL) || (format == NULL) || (sizeOfBuffer <= 0))))
@@ -118,7 +112,8 @@ _sxprintf(
     buffer[result] = _T('\0');
 #else
     /* Only zero terminate if there is enough space left */
-    if (stream._cnt >= sizeof(TCHAR)) *(TCHAR*)stream._ptr = _T('\0');
+    if ((stream._cnt >= sizeof(TCHAR)) && (stream._ptr))
+        *(TCHAR*)stream._ptr = _T('\0');
 #endif
 
     return result;
index 27b1471..0815543 100644 (file)
@@ -227,6 +227,9 @@ static
 int
 streamout_char(FILE *stream, int chr)
 {
+    if ((stream->_flag & _IOSTRG) && (!stream->_ptr))
+        return 1;
+
 #if defined(_USER32_WSPRINTF) || defined(_LIBCNT_)
     /* Check if the buffer is full */
     if (stream->_cnt < sizeof(TCHAR))