More accuracy checking result of MS VC _CRT _vsnprintf()

This commit is contained in:
Stas Degteff 2011-02-22 09:38:30 +00:00
parent 91e68866fc
commit acd96d47bc

View File

@ -48,7 +48,7 @@ int snprintf( char *buffer, size_t sizeOfBuffer, const char *format, ... )
va_list argptr; va_list argptr;
va_start(argptr, format); va_start(argptr, format);
int r = _vsnprintf( buffer, sizeOfBuffer, format, argptr ); int r = _vsnprintf( buffer, sizeOfBuffer, format, argptr );
if( r == -1 || r == sizeOfBuffer ) if( r == -1 || r >= sizeOfBuffer )
buffer[sizeOfBuffer-1] = '\0'; buffer[sizeOfBuffer-1] = '\0';
va_end(argptr); va_end(argptr);
return r; return r;
@ -57,7 +57,7 @@ int snprintf( char *buffer, size_t sizeOfBuffer, const char *format, ... )
int vsnprintf( char *buffer, size_t sizeOfBuffer, const char *format, va_list argptr ) int vsnprintf( char *buffer, size_t sizeOfBuffer, const char *format, va_list argptr )
{ {
int r = _vsnprintf( buffer, sizeOfBuffer, format, argptr ); int r = _vsnprintf( buffer, sizeOfBuffer, format, argptr );
if( r == -1 || r == sizeOfBuffer ) if( r == -1 || r >= sizeOfBuffer )
buffer[sizeOfBuffer-1] = '\0'; buffer[sizeOfBuffer-1] = '\0';
return r; return r;
} }