Jacek Caban : ntdll: Move null terminating result to pf_vsnprintf callers.
Alexandre Julliard
julliard at winehq.org
Wed Jul 3 17:11:54 CDT 2019
Module: wine
Branch: master
Commit: b350095b7660bd91c42d66ce12cd206586ea6b62
URL: https://source.winehq.org/git/wine.git/?a=commit;h=b350095b7660bd91c42d66ce12cd206586ea6b62
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Jul 3 21:06:14 2019 +0200
ntdll: Move null terminating result to pf_vsnprintf callers.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/printf.c | 48 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 38 insertions(+), 10 deletions(-)
diff --git a/dlls/ntdll/printf.c b/dlls/ntdll/printf.c
index c1a0194..6b7293b 100644
--- a/dlls/ntdll/printf.c
+++ b/dlls/ntdll/printf.c
@@ -75,17 +75,23 @@ 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)
+ {
+ out->used += len;
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 += space;
+ }
}
else
{
@@ -93,16 +99,23 @@ 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)
+ {
+ out->used += n;
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) );
+ if (space > 0)
+ {
+ RtlUnicodeToMultiByteN( p, space, NULL, str, len * sizeof(WCHAR) );
+ out->used += space;
+ }
}
return -1;
}
@@ -116,17 +129,23 @@ 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)
+ {
+ out->used += len;
return len;
+ }
if( space >= len )
{
memcpy( p, str, len );
+ out->used += len;
return len;
}
if( space > 0 )
+ {
memcpy( p, str, space );
+ out->used += space;
+ }
}
else
{
@@ -134,16 +153,23 @@ 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)
+ {
+ out->used += n / sizeof(WCHAR);
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 );
+ if (space > 0)
+ {
+ RtlMultiByteToUnicodeN( p, space * sizeof(WCHAR), NULL, str, len );
+ out->used += space;
+ }
}
return -1;
}
@@ -657,9 +683,7 @@ static int pf_vsnprintf( pf_output *out, const WCHAR *format, __ms_va_list valis
/* check we reached the end, and null terminate the string */
assert( *p == 0 );
- pf_output_stringW( out, p, 1 );
-
- return out->used - 1;
+ return out->used;
}
@@ -686,6 +710,7 @@ int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, __ms_va_l
}
r = pf_vsnprintf( &out, formatW, args );
RtlFreeHeap( GetProcessHeap(), 0, formatW );
+ if (out.used < len) str[out.used] = 0;
return r;
}
@@ -696,13 +721,16 @@ int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, __ms_va_l
int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args )
{
pf_output out;
+ int r;
out.unicode = TRUE;
out.buf.W = str;
out.used = 0;
out.len = len;
- return pf_vsnprintf( &out, format, args );
+ r = pf_vsnprintf( &out, format, args );
+ if (out.used < len) str[out.used] = 0;
+ return r;
}
More information about the wine-cvs
mailing list