forked from Mirrors/wine-wine
ntdll: Move null terminating result to pf_vsnprintf callers.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>stable
parent
51bc180c1f
commit
b350095b76
|
@ -75,17 +75,23 @@ 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)
|
if (!out->buf.W)
|
||||||
|
{
|
||||||
|
out->used += len;
|
||||||
return len;
|
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 += space;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -93,16 +99,23 @@ 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)
|
if (!out->buf.A)
|
||||||
|
{
|
||||||
|
out->used += n;
|
||||||
return len;
|
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 += space;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -116,17 +129,23 @@ 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)
|
if (!out->buf.A)
|
||||||
|
{
|
||||||
|
out->used += len;
|
||||||
return len;
|
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 += space;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -134,16 +153,23 @@ 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)
|
if (!out->buf.W)
|
||||||
|
{
|
||||||
|
out->used += n / sizeof(WCHAR);
|
||||||
return len;
|
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 += space;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
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 */
|
/* check we reached the end, and null terminate the string */
|
||||||
assert( *p == 0 );
|
assert( *p == 0 );
|
||||||
pf_output_stringW( out, p, 1 );
|
return out->used;
|
||||||
|
|
||||||
return out->used - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 );
|
r = pf_vsnprintf( &out, formatW, args );
|
||||||
RtlFreeHeap( GetProcessHeap(), 0, formatW );
|
RtlFreeHeap( GetProcessHeap(), 0, formatW );
|
||||||
|
if (out.used < len) str[out.used] = 0;
|
||||||
return r;
|
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 )
|
int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args )
|
||||||
{
|
{
|
||||||
pf_output out;
|
pf_output out;
|
||||||
|
int r;
|
||||||
|
|
||||||
out.unicode = TRUE;
|
out.unicode = TRUE;
|
||||||
out.buf.W = str;
|
out.buf.W = str;
|
||||||
out.used = 0;
|
out.used = 0;
|
||||||
out.len = len;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue