Commit 3c2dc4a7 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

ntdll: Allow passing NULL buffer to printf functions.

parent 73edf080
...@@ -75,16 +75,17 @@ static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len ) ...@@ -75,16 +75,17 @@ static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
if( out->unicode ) if( out->unicode )
{ {
LPWSTR p = out->buf.W + out->used; LPWSTR p = out->buf.W + out->used;
out->used += len;
if (!out->buf.W)
return len;
if( space >= len ) if( space >= len )
{ {
memcpy( p, str, len*sizeof(WCHAR) ); memcpy( p, str, len*sizeof(WCHAR) );
out->used += len;
return len; return len;
} }
if( space > 0 ) if( space > 0 )
memcpy( p, str, space*sizeof(WCHAR) ); memcpy( p, str, space*sizeof(WCHAR) );
out->used += len;
} }
else else
{ {
...@@ -92,14 +93,16 @@ static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len ) ...@@ -92,14 +93,16 @@ static inline int pf_output_stringW( pf_output *out, LPCWSTR str, int len )
ULONG n; ULONG n;
RtlUnicodeToMultiByteSize( &n, str, len * sizeof(WCHAR) ); RtlUnicodeToMultiByteSize( &n, str, len * sizeof(WCHAR) );
out->used += n;
if (!out->buf.A)
return len;
if( space >= n ) if( space >= n )
{ {
RtlUnicodeToMultiByteN( p, n, NULL, str, len * sizeof(WCHAR) ); RtlUnicodeToMultiByteN( p, n, NULL, str, len * sizeof(WCHAR) );
out->used += n;
return len; return len;
} }
if (space > 0) RtlUnicodeToMultiByteN( p, space, NULL, str, len * sizeof(WCHAR) ); if (space > 0) RtlUnicodeToMultiByteN( p, space, NULL, str, len * sizeof(WCHAR) );
out->used += n;
} }
return -1; return -1;
} }
...@@ -113,16 +116,17 @@ static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len ) ...@@ -113,16 +116,17 @@ static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
if( !out->unicode ) if( !out->unicode )
{ {
LPSTR p = out->buf.A + out->used; LPSTR p = out->buf.A + out->used;
out->used += len;
if (!out->buf.A)
return len;
if( space >= len ) if( space >= len )
{ {
memcpy( p, str, len ); memcpy( p, str, len );
out->used += len;
return len; return len;
} }
if( space > 0 ) if( space > 0 )
memcpy( p, str, space ); memcpy( p, str, space );
out->used += len;
} }
else else
{ {
...@@ -130,14 +134,16 @@ static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len ) ...@@ -130,14 +134,16 @@ static inline int pf_output_stringA( pf_output *out, LPCSTR str, int len )
ULONG n; ULONG n;
RtlMultiByteToUnicodeSize( &n, str, len ); RtlMultiByteToUnicodeSize( &n, str, len );
out->used += n / sizeof(WCHAR);
if (!out->buf.W)
return len;
if (space >= n / sizeof(WCHAR)) if (space >= n / sizeof(WCHAR))
{ {
RtlMultiByteToUnicodeN( p, n, NULL, str, len ); RtlMultiByteToUnicodeN( p, n, NULL, str, len );
out->used += n / sizeof(WCHAR);
return len; return len;
} }
if (space > 0) RtlMultiByteToUnicodeN( p, space * sizeof(WCHAR), NULL, str, len ); if (space > 0) RtlMultiByteToUnicodeN( p, space * sizeof(WCHAR), NULL, str, len );
out->used += n / sizeof(WCHAR);
} }
return -1; return -1;
} }
......
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