Merge pull request #363 from Dmitry-Me/outputLengthAsserts

Asserts for formatted output length
This commit is contained in:
Lee Thomason 2015-08-07 15:50:16 -07:00
commit 7ae888a601
1 changed files with 5 additions and 1 deletions

View File

@ -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.