remove random -1 in length

This commit is contained in:
Lee Thomason (grinliz) 2012-04-06 21:24:29 -07:00
parent 598c13efa8
commit a4a36ba3c2
2 changed files with 24 additions and 16 deletions

View File

@ -1005,7 +1005,7 @@ void XMLAttribute::SetAttribute( int v )
void XMLAttribute::SetAttribute( unsigned v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%u", v );
TIXML_SNPRINTF( buf, BUF_SIZE, "%u", v );
value.SetStr( buf );
}
@ -1013,21 +1013,21 @@ void XMLAttribute::SetAttribute( unsigned v )
void XMLAttribute::SetAttribute( bool v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%d", v ? 1 : 0 );
TIXML_SNPRINTF( buf, BUF_SIZE, "%d", v ? 1 : 0 );
value.SetStr( buf );
}
void XMLAttribute::SetAttribute( double v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%f", v );
TIXML_SNPRINTF( buf, BUF_SIZE, "%f", v );
value.SetStr( buf );
}
void XMLAttribute::SetAttribute( float v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%f", v );
TIXML_SNPRINTF( buf, BUF_SIZE, "%f", v );
value.SetStr( buf );
}
@ -1480,11 +1480,9 @@ void XMLDocument::PrintError() const
if ( errorStr1 ) {
TIXML_SNPRINTF( buf1, LEN, "%s", errorStr1 );
buf1[LEN-1] = 0;
}
if ( errorStr2 ) {
TIXML_SNPRINTF( buf2, LEN, "%s", errorStr2 );
buf2[LEN-1] = 0;
}
printf( "XMLDocument error id=%d str1=%s str2=%s\n",
@ -1643,7 +1641,7 @@ void XMLPrinter::PushAttribute( const char* name, const char* value )
void XMLPrinter::PushAttribute( const char* name, int v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%d", v );
TIXML_SNPRINTF( buf, BUF_SIZE, "%d", v );
PushAttribute( name, buf );
}
@ -1651,7 +1649,7 @@ void XMLPrinter::PushAttribute( const char* name, int v )
void XMLPrinter::PushAttribute( const char* name, unsigned v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%u", v );
TIXML_SNPRINTF( buf, BUF_SIZE, "%u", v );
PushAttribute( name, buf );
}
@ -1659,7 +1657,7 @@ void XMLPrinter::PushAttribute( const char* name, unsigned v )
void XMLPrinter::PushAttribute( const char* name, bool v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%d", v ? 1 : 0 );
TIXML_SNPRINTF( buf, BUF_SIZE, "%d", v ? 1 : 0 );
PushAttribute( name, buf );
}
@ -1667,7 +1665,7 @@ void XMLPrinter::PushAttribute( const char* name, bool v )
void XMLPrinter::PushAttribute( const char* name, double v )
{
char buf[BUF_SIZE];
TIXML_SNPRINTF( buf, BUF_SIZE-1, "%f", v );
TIXML_SNPRINTF( buf, BUF_SIZE, "%f", v );
PushAttribute( name, buf );
}

View File

@ -751,6 +751,16 @@ int main( int /*argc*/, const char ** /*argv*/ )
XMLTest( "Clone and Equal", 4, count );
}
{
// This shouldn't crash.
XMLDocument doc;
if(XML_NO_ERROR != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
{
doc.PrintError();
}
XMLTest( "Error in snprinf handling.", true, doc.Error() );
}
// ----------- Performance tracking --------------
{
#if defined( _MSC_VER )