ntdll: Allow passing NULL buffer to printf functions (try 3)

Sebastian Lackner sebastian at fds-team.de
Fri Dec 20 07:01:48 CST 2013


Note: the rest of the patches are still the same and can just be reused
from the previous submit. This patch assumes that at least #1 has been
applied before.

Thanks Julliard for pointing the unicode conversion problem, seems like
I had simplified this part a bit too much ;)

Changelog:
  * Take into account that MultiByteSize can vary from len

---
 dlls/ntdll/printf.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
-------------- next part --------------
From b41a076cbe437082bdad1f7eb646d14f49b60926 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian at fds-team.de>
Date: Fri, 20 Dec 2013 05:56:40 +0100
Subject: ntdll: Allow passing NULL buffer to printf functions

---
 dlls/ntdll/printf.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/printf.c b/dlls/ntdll/printf.c
index 3a5067a..b3efa00 100644
--- a/dlls/ntdll/printf.c
+++ b/dlls/ntdll/printf.c
@@ -75,16 +75,17 @@ static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
     if( out->unicode )
     {
         LPWSTR p = out->buf.W + out->used;
+        out->used += len;
 
+        if (!out->buf.W)
+            return len;
         if( space >= len )
         {
             memcpy( p, str, len*sizeof(WCHAR) );
-            out->used += len;
             return len;
         }
         if( space > 0 )
             memcpy( p, str, space*sizeof(WCHAR) );
-        out->used += len;
     }
     else
     {
@@ -92,14 +93,16 @@ static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
         ULONG n;
 
         RtlUnicodeToMultiByteSize( &n, str, len * sizeof(WCHAR) );
+        out->used += n;
+
+        if (!out->buf.A)
+            return len;
         if( space >= n )
         {
             RtlUnicodeToMultiByteN( p, n, NULL, str, len * sizeof(WCHAR) );
-            out->used += n;
             return len;
         }
         if (space > 0) RtlUnicodeToMultiByteN( p, space, NULL, str, len * sizeof(WCHAR) );
-        out->used += n;
     }
     return -1;
 }
@@ -113,16 +116,17 @@ static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
     if( !out->unicode )
     {
         LPSTR p = out->buf.A + out->used;
+        out->used += len;
 
+        if (!out->buf.A)
+            return len;
         if( space >= len )
         {
             memcpy( p, str, len );
-            out->used += len;
             return len;
         }
         if( space > 0 )
             memcpy( p, str, space );
-        out->used += len;
     }
     else
     {
@@ -130,14 +134,16 @@ static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
         ULONG n;
 
         RtlMultiByteToUnicodeSize( &n, str, len );
+        out->used += n / sizeof(WCHAR);
+
+        if (!out->buf.W)
+            return len;
         if (space >= n / sizeof(WCHAR))
         {
             RtlMultiByteToUnicodeN( p, n, NULL, str, len );
-            out->used += n / sizeof(WCHAR);
             return len;
         }
         if (space > 0) RtlMultiByteToUnicodeN( p, space * sizeof(WCHAR), NULL, str, len );
-        out->used += n / sizeof(WCHAR);
     }
     return -1;
 }
-- 
1.7.9.5


More information about the wine-patches mailing list