From acd96d47bcba19754ae55b36bb5e66ed99f9cc65 Mon Sep 17 00:00:00 2001 From: Stas Degteff Date: Tue, 22 Feb 2011 09:38:30 +0000 Subject: [PATCH] More accuracy checking result of MS VC _CRT _vsnprintf() --- goldlib/gall/gstrutil.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/goldlib/gall/gstrutil.cpp b/goldlib/gall/gstrutil.cpp index d5f7aca..8842f41 100644 --- a/goldlib/gall/gstrutil.cpp +++ b/goldlib/gall/gstrutil.cpp @@ -48,7 +48,7 @@ int snprintf( char *buffer, size_t sizeOfBuffer, const char *format, ... ) va_list argptr; va_start(argptr, format); int r = _vsnprintf( buffer, sizeOfBuffer, format, argptr ); - if( r == -1 || r == sizeOfBuffer ) + if( r == -1 || r >= sizeOfBuffer ) buffer[sizeOfBuffer-1] = '\0'; va_end(argptr); 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 r = _vsnprintf( buffer, sizeOfBuffer, format, argptr ); - if( r == -1 || r == sizeOfBuffer ) + if( r == -1 || r >= sizeOfBuffer ) buffer[sizeOfBuffer-1] = '\0'; return r; }