From a4a36ba3c2c98988b7a6a774061028014678c7f2 Mon Sep 17 00:00:00 2001 From: "Lee Thomason (grinliz)" Date: Fri, 6 Apr 2012 21:24:29 -0700 Subject: [PATCH] remove random -1 in length --- tinyxml2.cpp | 18 ++++++++---------- xmltest.cpp | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 72c2dac..f6998ea 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -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 ); } diff --git a/xmltest.cpp b/xmltest.cpp index bb5bdfb..29809e8 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -94,12 +94,12 @@ int example_2() int example_3() { - static const char* xml = - "" - "" - "" - "A Midsummer Night's Dream" - ""; + static const char* xml = + "" + "" + "" + "A Midsummer Night's Dream" + ""; XMLDocument doc; doc.Parse( xml ); @@ -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 )