From f9f3c3e85c018c8f03b32e53de258d410b04bfb3 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 30 Aug 2016 15:51:55 +0300 Subject: [PATCH 1/7] Loop invariant pointer assertions --- tinyxml2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index d26b483..0a28f68 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -191,6 +191,7 @@ void StrPair::SetStr( const char* str, int flags ) char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) { + TIXMLASSERT( p ); TIXMLASSERT( endTag && *endTag ); char* start = p; @@ -204,6 +205,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) return p + length; } ++p; + TIXMLASSERT( p ); } return 0; } From fed511276f1460fdea199ba386fce5b19e47627b Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 6 Sep 2016 18:08:55 +0300 Subject: [PATCH 2/7] Split access and pointer adjustment --- tinyxml2.cpp | 6 ++++-- tinyxml2.h | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 9a8904f..9d74681 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -281,7 +281,8 @@ const char* StrPair::GetStr() else { ++p; } - *q++ = LF; + *q = LF; + ++q; } else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { if ( *(p+1) == CR ) { @@ -290,7 +291,8 @@ const char* StrPair::GetStr() else { ++p; } - *q++ = LF; + *q = LF; + ++q; } else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { // Entities handled by tinyXML2: diff --git a/tinyxml2.h b/tinyxml2.h index 4379f01..0b5e3cc 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -211,7 +211,8 @@ public: void Push( T t ) { TIXMLASSERT( _size < INT_MAX ); EnsureCapacity( _size+1 ); - _mem[_size++] = t; + _mem[_size] = t; + ++_size; } T* PushArr( int count ) { @@ -225,7 +226,8 @@ public: T Pop() { TIXMLASSERT( _size > 0 ); - return _mem[--_size]; + --_size; + return _mem[_size]; } void PopArr( int count ) { From 3b9cf99916a2ef4ef286fa404ed9f6796fdcb778 Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Fri, 23 Sep 2016 18:42:23 -0600 Subject: [PATCH 3/7] Update comments to reflect single successful return type --- tinyxml2.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tinyxml2.h b/tinyxml2.h index 0b5e3cc..8d5eb2a 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1129,7 +1129,7 @@ public: } /** QueryIntValue interprets the attribute as an integer, and returns the value - in the provided parameter. The function will return XML_NO_ERROR on success, + in the provided parameter. The function will return XML_SUCCESS on success, and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. */ XMLError QueryIntValue( int* value ) const; @@ -1273,7 +1273,7 @@ public: } /** Given an attribute name, QueryIntAttribute() returns - XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion + XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. If successful, the result of the conversion will be written to 'value'. If not successful, nothing will @@ -1338,7 +1338,7 @@ public: /** Given an attribute name, QueryAttribute() returns - XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion + XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion can't be performed, or XML_NO_ATTRIBUTE if the attribute doesn't exist. It is overloaded for the primitive types, and is a generally more convenient replacement of @@ -1612,7 +1612,7 @@ public: /** Parse an XML file from a character string. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. You may optionally pass in the 'nBytes', which is @@ -1624,7 +1624,7 @@ public: /** Load an XML file from disk. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError LoadFile( const char* filename ); @@ -1637,14 +1637,14 @@ public: not text in order for TinyXML-2 to correctly do newline normalization. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError LoadFile( FILE* ); /** Save the XML file to disk. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError SaveFile( const char* filename, bool compact = false ); @@ -1653,7 +1653,7 @@ public: Save the XML file to disk. You are responsible for providing and closing the FILE*. - Returns XML_NO_ERROR (0) on success, or + Returns XML_SUCCESS (0) on success, or an errorID. */ XMLError SaveFile( FILE* fp, bool compact = false ); From aad61870a95bdab54a297b8c383d381e4f5228d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kury=C5=82o?= Date: Thu, 29 Sep 2016 18:47:51 +0200 Subject: [PATCH 4/7] Fix cmake warnings on new cmake versions. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec2e58f..e9b44d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ IF(BIICODE) ENDIF(BIICODE) cmake_minimum_required(VERSION 2.6 FATAL_ERROR) cmake_policy(VERSION 2.6) +if(POLICY CMP0063) + cmake_policy(SET CMP0063 OLD) +endif() project(tinyxml2) include(GNUInstallDirs) From 21f996960d09fe468ff3ff522f06ed6df6ee88fd Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 3 Oct 2016 13:01:57 +0300 Subject: [PATCH 5/7] Assertions in string comparison --- tinyxml2.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tinyxml2.h b/tinyxml2.h index 8d5eb2a..fbfe4f6 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -570,6 +570,9 @@ public: if ( p == q ) { return true; } + TIXMLASSERT( p ); + TIXMLASSERT( q ); + TIXMLASSERT( nChar >= 0 ); return strncmp( p, q, nChar ) == 0; } From 3c97724d0e328ef58cdc0f1e7b19ad172da0840b Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Thu, 6 Oct 2016 16:05:59 -0700 Subject: [PATCH 6/7] Fix typo --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 82c6ce9..63f98fe 100644 --- a/readme.md +++ b/readme.md @@ -111,7 +111,7 @@ by the Document. When the Document is deleted, so are all the nodes it contains. Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx -By default, TinyXML-2 preserves white space in a (hopefully) sane way that is almost complient with the +By default, TinyXML-2 preserves white space in a (hopefully) sane way that is almost compliant with the spec. (TinyXML-1 used a completely different model, much more similar to 'collapse', below.) As a first step, all newlines / carriage-returns / line-feeds are normalized to a From 318252a973511fdf87af1830edd13eb801ee7c59 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Fri, 7 Oct 2016 10:37:02 -0700 Subject: [PATCH 7/7] Fix warning on PowerPC GCC 5+ will generate "error: comparison is always true due to limited range of data type" when -Wextra is used because PowerPC by default uses unsigned char, so it can never be less than 0. --- tinyxml2.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index c872a54..7df8443 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2183,7 +2183,8 @@ XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : } for( int i=0; i(entityValue) && entityValue < ENTITY_RANGE ); _entityFlag[ (unsigned char)entityValue ] = true; } _restrictedEntityFlag[(unsigned char)'&'] = true;