From be69ae63521e9c3d12a45ef64de58405d263ba71 Mon Sep 17 00:00:00 2001 From: Derek Quam Date: Wed, 18 Apr 2018 13:40:46 -0500 Subject: [PATCH] In PrintString, move the optimization under the if ( _processEntities ) block and retain the strlen Write in the new else block. Added a test case. --- tinyxml2.cpp | 16 +++++++++------- xmltest.cpp | 11 +++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 89b7913..33cf19f 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2523,14 +2523,16 @@ void XMLPrinter::PrintString( const char* p, bool restricted ) ++q; TIXMLASSERT( p <= q ); } + // Flush the remaining string. This will be the entire + // string if an entity wasn't found. + if ( p < q ) { + const size_t delta = q - p; + const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta; + Write( p, toPrint ); + } } - // Flush the remaining string. This will be the entire - // string if an entity wasn't found. - TIXMLASSERT( p <= q ); - if ( !_processEntities || ( p < q ) ) { - const size_t delta = q - p; - const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta; - Write( p, toPrint ); + else { + Write( p ); } } diff --git a/xmltest.cpp b/xmltest.cpp index 7160fe9..26443aa 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1995,6 +1995,17 @@ int main( int argc, const char ** argv ) } } + { + const char* html("

test


"); + XMLDocument doc(false); + doc.Parse(html); + + XMLPrinter printer(0, true); + doc.Print(&printer); + + XMLTest(html, html, printer.CStr()); + } + { // Evil memory leaks. // If an XMLElement (etc) is allocated via NewElement() (etc.)