From 1d32e586d563ba0aaa5e5e54d802c105f73adf74 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 27 Jul 2015 17:11:51 +0300 Subject: [PATCH] Asserts for formatted output length --- tinyxml2.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index edf714d..3f45d1a 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -75,10 +75,12 @@ distribution. const int required = _vsnprintf(str, len, format, va); delete[] str; if ( required != -1 ) { + TIXMLASSERT( required >= 0 ); len = required; break; } } + TIXMLASSERT( len >= 0 ); return len; } #endif @@ -90,6 +92,7 @@ distribution. inline int TIXML_VSCPRINTF( const char* format, va_list va ) { int len = vsnprintf( 0, 0, format, va ); + TIXMLASSERT( len >= 0 ); return len; } #define TIXML_SSCANF sscanf @@ -2105,9 +2108,10 @@ void XMLPrinter::Print( const char* format, ... ) vfprintf( _fp, format, va ); } else { - int len = TIXML_VSCPRINTF( format, va ); + const int len = TIXML_VSCPRINTF( format, va ); // Close out and re-start the va-args va_end( va ); + TIXMLASSERT( len >= 0 ); va_start( va, format ); TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 ); char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator.