From ef11c2f8ec2adf0d5c6bfbf1f35812231d9470f3 Mon Sep 17 00:00:00 2001 From: DragonValley Date: Sat, 15 Jul 2017 05:53:26 +0200 Subject: [PATCH 1/6] Update on html5-printer.cpp Instead of: #include , it is better to go with #include "tinyxml2.h" so it doesn't search for tinyxml2 library in system libraries but the current directory. --- contrib/html5-printer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/html5-printer.cpp b/contrib/html5-printer.cpp index 7728b69..92cff2b 100644 --- a/contrib/html5-printer.cpp +++ b/contrib/html5-printer.cpp @@ -40,7 +40,7 @@ distribution. */ -#include +#include "tinyxml2.h" #include #if defined (_MSC_VER) From f0f506fe5a75003309a3b6eebe3e652daf261b65 Mon Sep 17 00:00:00 2001 From: DragonValley Date: Wed, 19 Jul 2017 22:24:23 +0200 Subject: [PATCH 2/6] Update html5-printer.cpp --- contrib/html5-printer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/html5-printer.cpp b/contrib/html5-printer.cpp index 92cff2b..e9a423d 100644 --- a/contrib/html5-printer.cpp +++ b/contrib/html5-printer.cpp @@ -40,7 +40,7 @@ distribution. */ -#include "tinyxml2.h" +#include "../tinyxml2.h" #include #if defined (_MSC_VER) From 7f0f754cb74d18f877332089b5b30055aa060f3b Mon Sep 17 00:00:00 2001 From: Thierry Lelegard Date: Fri, 1 Sep 2017 10:14:16 +0200 Subject: [PATCH 3/6] Code cleanup to pass gcc -Weffc++ warnings --- Makefile | 7 +++++++ tinyxml2.cpp | 14 ++++++++++++-- tinyxml2.h | 35 +++++++++++++++++------------------ xmltest.cpp | 2 ++ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index eba6fef..4532fa1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,10 @@ +# Extended C++ warning policy +CXXFLAGS += -Werror -Wall -Wextra -Wshadow -Wpedantic -Wformat-nonliteral \ + -Wformat-security -Wswitch-default -Wuninitialized -Wundef \ + -Wpointer-arith -Woverloaded-virtual -Wctor-dtor-privacy \ + -Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo \ + -Wno-unused-parameter -Weffc++ + all: xmltest staticlib rebuild: clean all diff --git a/tinyxml2.cpp b/tinyxml2.cpp index a8a4a20..8f0116b 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -741,6 +741,7 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const XMLNode::XMLNode( XMLDocument* doc ) : _document( doc ), _parent( 0 ), + _value(), _parseLineNum( 0 ), _firstChild( 0 ), _lastChild( 0 ), _prev( 0 ), _next( 0 ), @@ -1993,9 +1994,16 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : _processEntities( processEntities ), _errorID(XML_SUCCESS), _whitespaceMode( whitespaceMode ), + _errorStr1(), + _errorStr2(), _errorLineNum( 0 ), _charBuffer( 0 ), - _parseCurLineNum( 0 ) + _parseCurLineNum( 0 ), + _unlinked(), + _elementPool(), + _attributePool(), + _textPool(), + _commentPool() { // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) _document = this; @@ -2367,12 +2375,14 @@ void XMLDocument::Parse() XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : _elementJustOpened( false ), + _stack(), _firstElement( true ), _fp( file ), _depth( depth ), _textDepth( -1 ), _processEntities( true ), - _compactMode( compact ) + _compactMode( compact ), + _buffer() { for( int i=0; i class DynArray { public: - DynArray() { - _mem = _pool; - _allocated = INITIAL_SIZE; - _size = 0; + DynArray() : + _mem( _pool ), + _allocated( INITIAL_SIZE ), + _size( 0 ) + { } ~DynArray() { @@ -333,7 +334,7 @@ template< int ITEM_SIZE > class MemPoolT : public MemPool { public: - MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} + MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} ~MemPoolT() { Clear(); } @@ -1211,7 +1212,7 @@ public: private: enum { BUF_SIZE = 200 }; - XMLAttribute() : _parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} + XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} virtual ~XMLAttribute() {} XMLAttribute( const XMLAttribute& ); // not supported @@ -1947,16 +1948,13 @@ class TINYXML2_LIB XMLHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - XMLHandle( XMLNode* node ) { - _node = node; + XMLHandle( XMLNode* node ) : _node( node ) { } /// Create a handle from a node. - XMLHandle( XMLNode& node ) { - _node = &node; + XMLHandle( XMLNode& node ) : _node( &node ) { } /// Copy constructor - XMLHandle( const XMLHandle& ref ) { - _node = ref._node; + XMLHandle( const XMLHandle& ref ) : _node( ref._node ) { } /// Assignment XMLHandle& operator=( const XMLHandle& ref ) { @@ -2030,14 +2028,11 @@ private: class TINYXML2_LIB XMLConstHandle { public: - XMLConstHandle( const XMLNode* node ) { - _node = node; + XMLConstHandle( const XMLNode* node ) : _node( node ) { } - XMLConstHandle( const XMLNode& node ) { - _node = &node; + XMLConstHandle( const XMLNode& node ) : _node( &node ) { } - XMLConstHandle( const XMLConstHandle& ref ) { - _node = ref._node; + XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) { } XMLConstHandle& operator=( const XMLConstHandle& ref ) { @@ -2252,6 +2247,10 @@ private: bool _restrictedEntityFlag[ENTITY_RANGE]; DynArray< char, 20 > _buffer; + + // Prohibit cloning, intentionally not implemented + XMLPrinter( const XMLPrinter& ); + XMLPrinter& operator=( const XMLPrinter& ); }; diff --git a/xmltest.cpp b/xmltest.cpp index 59724f7..1c07faa 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -2017,6 +2017,8 @@ int main( int argc, const char ** argv ) { struct TestUtil: XMLVisitor { + TestUtil() : str() {} + void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine) { XMLDocument doc; From f0f2e99cf286b971a849ba351d860cf909245fb6 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 25 Sep 2017 17:38:42 +0300 Subject: [PATCH 4/6] Check result of Accept() --- xmltest.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/xmltest.cpp b/xmltest.cpp index 96cbf64..5c507a4 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1035,8 +1035,9 @@ int main( int argc, const char ** argv ) if ( textfile ) { XMLPrinter streamer( textfile ); - psg->Accept( &streamer ); + bool acceptResult = psg->Accept( &streamer ); fclose( textfile ); + XMLTest( "Entity transformation: Accept", true, acceptResult ); } textfile = fopen( textFilePath, "r" ); @@ -1332,7 +1333,8 @@ int main( int argc, const char ** argv ) XMLTest( "Parse before deep cloning sub element", false, doc.Error() ); const XMLElement* subElement = doc.FirstChildElement("root")->FirstChildElement("child2"); - subElement->Accept(&printer1); + bool acceptResult = subElement->Accept(&printer1); + XMLTest( "Accept before deep cloning", true, acceptResult ); XMLNode* clonedSubElement = subElement->DeepClone(&doc2); doc2.InsertFirstChild(clonedSubElement); @@ -1648,7 +1650,8 @@ int main( int argc, const char ** argv ) XMLElement* ele = doc.FirstChildElement( "parent")->FirstChildElement( "child"); XMLPrinter printer; - ele->Accept( &printer ); + bool acceptResult = ele->Accept( &printer ); + XMLTest( "Accept of sub-element", true, acceptResult ); XMLTest( "Printing of sub-element", "abc\n", printer.CStr(), false ); } @@ -1730,7 +1733,8 @@ int main( int argc, const char ** argv ) XMLElement* two = doc.RootElement()->FirstChildElement("two"); two->InsertFirstChild(subtree); XMLPrinter printer1(0, true); - doc.Accept(&printer1); + bool acceptResult = doc.Accept(&printer1); + XMLTest("Move node from within to - Accept()", true, acceptResult); XMLTest("Move node from within to ", xmlInsideTwo, printer1.CStr()); doc.Parse(xml); @@ -1739,7 +1743,8 @@ int main( int argc, const char ** argv ) two = doc.RootElement()->FirstChildElement("two"); doc.RootElement()->InsertAfterChild(two, subtree); XMLPrinter printer2(0, true); - doc.Accept(&printer2); + acceptResult = doc.Accept(&printer2); + XMLTest("Move node from within after - Accept()", true, acceptResult); XMLTest("Move node from within after ", xmlAfterTwo, printer2.CStr(), false); doc.Parse(xml); @@ -1748,7 +1753,8 @@ int main( int argc, const char ** argv ) subtree = one->FirstChildElement("subtree"); doc.RootElement()->InsertAfterChild(one, subtree); XMLPrinter printer3(0, true); - doc.Accept(&printer3); + acceptResult = doc.Accept(&printer3); + XMLTest("Move node from within after - Accept()", true, acceptResult); XMLTest("Move node from within after ", xmlAfterOne, printer3.CStr(), false); doc.Parse(xml); @@ -1757,7 +1763,8 @@ int main( int argc, const char ** argv ) two = doc.RootElement()->FirstChildElement("two"); doc.RootElement()->InsertEndChild(subtree); XMLPrinter printer4(0, true); - doc.Accept(&printer4); + acceptResult = doc.Accept(&printer4); + XMLTest("Move node from within after - Accept()", true, acceptResult); XMLTest("Move node from within after ", xmlAfterTwo, printer4.CStr(), false); } @@ -1881,7 +1888,8 @@ int main( int argc, const char ** argv ) XMLDocument doc; XMLElement* newElement = doc.NewElement( "printme" ); XMLPrinter printer; - newElement->Accept( &printer ); + bool acceptResult = newElement->Accept( &printer ); + XMLTest( "printme - Accept()", true, acceptResult ); // Delete the node to avoid possible memory leak report in debug output doc.DeleteNode( newElement ); } @@ -2032,7 +2040,8 @@ int main( int argc, const char ** argv ) }; tinyxml2::XMLPrinter printer; - playlist->Accept(&printer); + const bool acceptResult = playlist->Accept(&printer); + XMLTest("Crash bug parsing - Accept()", true, acceptResult); printf("%s\n", printer.CStr()); // No test; it only need to not crash. @@ -2121,7 +2130,8 @@ int main( int argc, const char ** argv ) void TestDocLines(const char *testString, XMLDocument &doc, const char *expectedLines) { str.Clear(); - doc.Accept(this); + const bool acceptResult = doc.Accept(this); + XMLTest(testString, true, acceptResult); str.Push(0); XMLTest(testString, expectedLines, str.Mem()); } From b41e24aa1cf9fcb43c6bcc71cd19c540681abf4f Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Wed, 27 Sep 2017 18:51:01 +0300 Subject: [PATCH 5/6] Better test deletion loop --- xmltest.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/xmltest.cpp b/xmltest.cpp index 96cbf64..d402787 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -2017,19 +2017,29 @@ int main( int argc, const char ** argv ) XMLElement* playlist = doc.FirstChildElement("playlist"); XMLTest("Crash bug parsing", true, playlist != 0); - tinyxml2::XMLElement* entry = playlist->FirstChildElement("entry"); - XMLTest("Crash bug parsing", true, entry != 0); - while (entry) { - tinyxml2::XMLElement* todelete = entry; - entry = entry->NextSiblingElement("entry"); - playlist->DeleteChild(todelete); - }; - tinyxml2::XMLElement* blank = playlist->FirstChildElement("blank"); - while (blank) { - tinyxml2::XMLElement* todelete = blank; - blank = blank->NextSiblingElement("blank"); - playlist->DeleteChild(todelete); - }; + { + const char* elementName = "entry"; + XMLElement* entry = playlist->FirstChildElement(elementName); + XMLTest("Crash bug parsing", true, entry != 0); + while (entry) { + XMLElement* todelete = entry; + entry = entry->NextSiblingElement(elementName); + playlist->DeleteChild(todelete); + } + entry = playlist->FirstChildElement(elementName); + XMLTest("Crash bug parsing", true, entry == 0); + } + { + const char* elementName = "blank"; + XMLElement* blank = playlist->FirstChildElement(elementName); + XMLTest("Crash bug parsing", true, blank != 0); + while (blank) { + XMLElement* todelete = blank; + blank = blank->NextSiblingElement(elementName); + playlist->DeleteChild(todelete); + } + XMLTest("Crash bug parsing", true, blank == 0); + } tinyxml2::XMLPrinter printer; playlist->Accept(&printer); From 8b83b238767ca1fdaaf73b3f4a1b98c4512a54bb Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Wed, 11 Oct 2017 10:13:35 -0700 Subject: [PATCH 6/6] make effc compilation optional --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4532fa1..f26cd92 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ -# Extended C++ warning policy -CXXFLAGS += -Werror -Wall -Wextra -Wshadow -Wpedantic -Wformat-nonliteral \ - -Wformat-security -Wswitch-default -Wuninitialized -Wundef \ - -Wpointer-arith -Woverloaded-virtual -Wctor-dtor-privacy \ - -Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo \ - -Wno-unused-parameter -Weffc++ - all: xmltest staticlib rebuild: clean all xmltest: xmltest.cpp libtinyxml2.a +effc: + gcc -Werror -Wall -Wextra -Wshadow -Wpedantic -Wformat-nonliteral \ + -Wformat-security -Wswitch-default -Wuninitialized -Wundef \ + -Wpointer-arith -Woverloaded-virtual -Wctor-dtor-privacy \ + -Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo \ + -Wno-unused-parameter -Weffc++ xmltest.cpp tinyxml2.cpp -o xmltest + clean: $(RM) *.o xmltest libtinyxml2.a