From aa1883928bf20605db7ac1193c016364b580c85c Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Tue, 19 Sep 2017 17:54:31 -0700 Subject: [PATCH 1/5] Error string re-work --- tinyxml2.cpp | 84 ++++++++++++++++++++++++++-------------------------- tinyxml2.h | 12 +++----- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index dcf2a43..1b54017 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -165,6 +165,7 @@ void StrPair::TransferTo( StrPair* other ) _end = 0; } + void StrPair::Reset() { if ( _flags & NEEDS_DELETE ) { @@ -1018,7 +1019,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) if ( !p ) { DeleteNode( node ); if ( !_document->Error() ) { - _document->SetError( XML_ERROR_PARSING, 0, 0, initialLineNum); + _document->SetError( XML_ERROR_PARSING, initialLineNum, 0); } break; } @@ -1038,7 +1039,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) } } if ( !wellLocated ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0, initialLineNum); + _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "value: %s", decl->Value()); DeleteNode( node ); break; } @@ -1073,7 +1074,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) } } if ( mismatch ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, ele->Name(), 0, initialLineNum); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "name=%s", ele->Name()); DeleteNode( node ); break; } @@ -1134,7 +1135,7 @@ char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) if ( this->CData() ) { p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { - _document->SetError( XML_ERROR_PARSING_CDATA, start, 0, _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_CDATA, _parseLineNum, 0 ); } return p; } @@ -1149,7 +1150,7 @@ char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) return p-1; } if ( !p ) { - _document->SetError( XML_ERROR_PARSING_TEXT, start, 0, _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, 0 ); } } return 0; @@ -1200,7 +1201,7 @@ char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) const char* start = p; p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr ); if ( p == 0 ) { - _document->SetError( XML_ERROR_PARSING_COMMENT, start, 0, _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 ); } return p; } @@ -1250,7 +1251,7 @@ char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) const char* start = p; p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( p == 0 ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0, _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 ); } return p; } @@ -1300,7 +1301,7 @@ char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { - _document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0, _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 ); } return p; } @@ -1810,7 +1811,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) while( p ) { p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( !(*p) ) { - _document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name(), _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "element name=%s", Name() ); return 0; } @@ -1825,7 +1826,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr ); if ( !p || Attribute( attrib->Name() ) ) { DeleteAttribute( attrib ); - _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p, attrLineNum ); + _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "element name=%s", Name() ); return 0; } // There is a minor bug here: if the attribute in the source xml @@ -1854,7 +1855,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) return p+2; // done; sealed element. } else { - _document->SetError( XML_ERROR_PARSING_ELEMENT, start, p, _parseLineNum ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0 ); return 0; } } @@ -2152,7 +2153,7 @@ XMLError XMLDocument::LoadFile( const char* filename ) Clear(); FILE* fp = callfopen( filename, "rb" ); if ( !fp ) { - SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0, 0 ); + SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ); return _errorID; } LoadFile( fp ); @@ -2189,7 +2190,7 @@ XMLError XMLDocument::LoadFile( FILE* fp ) fseek( fp, 0, SEEK_SET ); if ( fgetc( fp ) == EOF && ferror( fp ) != 0 ) { - SetError( XML_ERROR_FILE_READ_ERROR, 0, 0, 0 ); + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } @@ -2197,19 +2198,19 @@ XMLError XMLDocument::LoadFile( FILE* fp ) const long filelength = ftell( fp ); fseek( fp, 0, SEEK_SET ); if ( filelength == -1L ) { - SetError( XML_ERROR_FILE_READ_ERROR, 0, 0, 0 ); + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } TIXMLASSERT( filelength >= 0 ); if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) { // Cannot handle files which won't fit in buffer together with null terminator - SetError( XML_ERROR_FILE_READ_ERROR, 0, 0, 0 ); + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } if ( filelength == 0 ) { - SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0, 0 ); + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } @@ -2218,7 +2219,7 @@ XMLError XMLDocument::LoadFile( FILE* fp ) _charBuffer = new char[size+1]; size_t read = fread( _charBuffer, 1, size, fp ); if ( read != size ) { - SetError( XML_ERROR_FILE_READ_ERROR, 0, 0, 0 ); + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); return _errorID; } @@ -2233,7 +2234,7 @@ XMLError XMLDocument::SaveFile( const char* filename, bool compact ) { FILE* fp = callfopen( filename, "w" ); if ( !fp ) { - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0, 0 ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ); return _errorID; } SaveFile(fp, compact); @@ -2258,7 +2259,7 @@ XMLError XMLDocument::Parse( const char* p, size_t len ) Clear(); if ( len == 0 || !p || !*p ) { - SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0, 0 ); + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } if ( len == (size_t)(-1) ) { @@ -2296,21 +2297,29 @@ void XMLDocument::Print( XMLPrinter* streamer ) const } -void XMLDocument::SetError( XMLError error, const char* str1, const char* str2, int lineNum ) +void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... ) { TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT ); _errorID = error; - - _errorStr1.Reset(); - _errorStr2.Reset(); - _errorLineNum = lineNum; + _errorStr.Reset(); - if (str1) - _errorStr1.SetStr(str1); - if (str2) - _errorStr2.SetStr(str2); + if (format) { + size_t BUFFER_SIZE = 1000; + char* buffer = new char[BUFFER_SIZE]; + TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d line=%d ", ErrorIDToName(error), int(error), lineNum); + size_t len = strlen(buffer); + + va_list va; + va_start( va, format ); + int result = TIXML_VSNPRINTF( buffer + len, BUFFER_SIZE - len, format, va ); + va_end( va ); + + _errorStr.SetStr(buffer); + delete [] buffer; + } } + /*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID) { TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT ); @@ -2319,14 +2328,9 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2, return errorName; } -const char* XMLDocument::GetErrorStr1() const +const char* XMLDocument::GetErrorStr() const { - return _errorStr1.GetStr(); -} - -const char* XMLDocument::GetErrorStr2() const -{ - return _errorStr2.GetStr(); + return _errorStr.Empty() ? "" : _errorStr.GetStr(); } const char* XMLDocument::ErrorName() const @@ -2341,13 +2345,9 @@ void XMLDocument::PrintError() const char buf1[LEN] = { 0 }; char buf2[LEN] = { 0 }; - if ( !_errorStr1.Empty() ) { - TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1.GetStr() ); + if ( !_errorStr.Empty() ) { + TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr.GetStr() ); } - if ( !_errorStr2.Empty() ) { - TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2.GetStr() ); - } - // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX ); @@ -2366,7 +2366,7 @@ void XMLDocument::Parse() p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); p = const_cast( XMLUtil::ReadBOM( p, &_writeBOM ) ); if ( !*p ) { - SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0, 0 ); + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return; } ParseDeep(p, 0, &_parseCurLineNum ); diff --git a/tinyxml2.h b/tinyxml2.h index 7b5bb0e..ecab407 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1785,10 +1785,10 @@ public: */ void DeleteNode( XMLNode* node ); - void SetError( XMLError error, const char* str1, const char* str2, int lineNum ); + void SetError( XMLError error, int lineNum, const char* format, ... ); void ClearError() { - SetError(XML_SUCCESS, 0, 0, 0); + SetError(XML_SUCCESS, 0, 0); } /// Return true if there was an error parsing the document. @@ -1803,10 +1803,7 @@ public: static const char* ErrorIDToName(XMLError errorID); /// Return a possibly helpful diagnostic location or string. - const char* GetErrorStr1() const; - - /// Return a possibly helpful secondary diagnostic location or string. - const char* GetErrorStr2() const; + const char* GetErrorStr() const; /// Return the line where the error occured, or zero if unknown. int GetErrorLineNum() const @@ -1849,8 +1846,7 @@ private: bool _processEntities; XMLError _errorID; Whitespace _whitespaceMode; - mutable StrPair _errorStr1; - mutable StrPair _errorStr2; + mutable StrPair _errorStr; int _errorLineNum; char* _charBuffer; int _parseCurLineNum; From 714ccfe29b143874d88e6fb736abea6baf1322b8 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Tue, 10 Oct 2017 17:08:12 -0700 Subject: [PATCH 2/5] fix line number tracker. error msg wip --- tinyxml2.cpp | 1 + xmltest.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 1b54017..140df86 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2301,6 +2301,7 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... { TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT ); _errorID = error; + _errorLineNum = lineNum; _errorStr.Reset(); if (format) { diff --git a/xmltest.cpp b/xmltest.cpp index 96cbf64..01b5011 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -499,9 +499,13 @@ int main( int argc, const char ** argv ) int value2 = doc->FirstChildElement()->LastChildElement()->IntAttribute( "attrib", replacementIntValue ); XMLError result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value1 ); XMLTest( "Programmatic DOM", XML_NO_ATTRIBUTE, result ); + doc->PrintError(); XMLTest( "Programmatic DOM", defaultIntValue, value1 ); XMLTest( "Programmatic DOM", replacementIntValue, value2 ); + + exit(0); + doc->Print(); { From f49b9658bb01702e9ab1dadf1486c32b5abcd68a Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Wed, 11 Oct 2017 10:57:49 -0700 Subject: [PATCH 3/5] fix up error system issues --- tinyxml2.cpp | 40 ++++++++++++++-------------------------- tinyxml2.h | 24 +++++++++++++++++------- xmltest.cpp | 26 ++++++++++++++++---------- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 140df86..3ec4f6d 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1039,7 +1039,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) } } if ( !wellLocated ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "value: %s", decl->Value()); + _document->SetError( XML_ERROR_PARSING_DECLARATION, initialLineNum, "XMLDeclaration value=%s", decl->Value()); DeleteNode( node ); break; } @@ -1074,7 +1074,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) } } if ( mismatch ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "name=%s", ele->Name()); + _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, initialLineNum, "XMLElement name=%s", ele->Name()); DeleteNode( node ); break; } @@ -1811,7 +1811,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) while( p ) { p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); if ( !(*p) ) { - _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "element name=%s", Name() ); + _document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() ); return 0; } @@ -1826,7 +1826,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) p = attrib->ParseDeep( p, _document->ProcessEntities(), curLineNumPtr ); if ( !p || Attribute( attrib->Name() ) ) { DeleteAttribute( attrib ); - _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "element name=%s", Name() ); + _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() ); return 0; } // There is a minor bug here: if the attribute in the source xml @@ -2153,7 +2153,7 @@ XMLError XMLDocument::LoadFile( const char* filename ) Clear(); FILE* fp = callfopen( filename, "rb" ); if ( !fp ) { - SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ); + SetError( XML_ERROR_FILE_NOT_FOUND, 0, "filename=%s", filename ? filename : ""); return _errorID; } LoadFile( fp ); @@ -2234,7 +2234,7 @@ XMLError XMLDocument::SaveFile( const char* filename, bool compact ) { FILE* fp = callfopen( filename, "w" ); if ( !fp ) { - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ); + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, "filename=%s", filename ? filename : ""); return _errorID; } SaveFile(fp, compact); @@ -2307,7 +2307,7 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... if (format) { size_t BUFFER_SIZE = 1000; char* buffer = new char[BUFFER_SIZE]; - TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d line=%d ", ErrorIDToName(error), int(error), lineNum); + TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d: ", ErrorIDToName(error), int(error), int(error), lineNum); size_t len = strlen(buffer); va_list va; @@ -2329,34 +2329,22 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... return errorName; } -const char* XMLDocument::GetErrorStr() const +const char* XMLDocument::ErrorStr() const { return _errorStr.Empty() ? "" : _errorStr.GetStr(); } + +void XMLDocument::PrintError() const +{ + printf("%s\n", ErrorStr()); +} + const char* XMLDocument::ErrorName() const { return ErrorIDToName(_errorID); } -void XMLDocument::PrintError() const -{ - if ( Error() ) { - static const int LEN = 20; - char buf1[LEN] = { 0 }; - char buf2[LEN] = { 0 }; - - if ( !_errorStr.Empty() ) { - TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr.GetStr() ); - } - // Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that - // causes a clang "always true" -Wtautological-constant-out-of-range-compare warning - TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX ); - printf( "XMLDocument error id=%d '%s' str1=%s str2=%s line=%d\n", - static_cast( _errorID ), ErrorName(), buf1, buf2, _errorLineNum ); - } -} - void XMLDocument::Parse() { TIXMLASSERT( NoChildren() ); // Clear() must have been called previously diff --git a/tinyxml2.h b/tinyxml2.h index ecab407..c9850f6 100755 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -1634,6 +1634,13 @@ enum Whitespace { class TINYXML2_LIB XMLDocument : public XMLNode { friend class XMLElement; + // Gives access to SetError, but over-access for everything else. + // Wishing C++ had "internal" scope. + friend class XMLNode; + friend class XMLText; + friend class XMLComment; + friend class XMLDeclaration; + friend class XMLUnknown; public: /// constructor XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE ); @@ -1785,8 +1792,6 @@ public: */ void DeleteNode( XMLNode* node ); - void SetError( XMLError error, int lineNum, const char* format, ... ); - void ClearError() { SetError(XML_SUCCESS, 0, 0); } @@ -1802,16 +1807,19 @@ public: const char* ErrorName() const; static const char* ErrorIDToName(XMLError errorID); - /// Return a possibly helpful diagnostic location or string. - const char* GetErrorStr() const; + /** Returns a "long form" error description. A hopefully helpful + diagnostic with location, line number, and/or additional info. + */ + const char* ErrorStr() const; + + /// A (trivial) utility function that prints the ErrorStr() to stdout. + void PrintError() const; /// Return the line where the error occured, or zero if unknown. - int GetErrorLineNum() const + int ErrorLineNum() const { return _errorLineNum; } - /// If there is an error, print it to stdout. - void PrintError() const; /// Clear the document, resetting it to the initial state. void Clear(); @@ -1867,6 +1875,8 @@ private: void Parse(); + void SetError( XMLError error, int lineNum, const char* format, ... ); + template NodeType* CreateUnlinkedNode( MemPoolT& pool ); }; diff --git a/xmltest.cpp b/xmltest.cpp index 01b5011..a297722 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -499,13 +499,9 @@ int main( int argc, const char ** argv ) int value2 = doc->FirstChildElement()->LastChildElement()->IntAttribute( "attrib", replacementIntValue ); XMLError result = doc->FirstChildElement()->LastChildElement()->QueryIntAttribute( "attrib", &value1 ); XMLTest( "Programmatic DOM", XML_NO_ATTRIBUTE, result ); - doc->PrintError(); XMLTest( "Programmatic DOM", defaultIntValue, value1 ); XMLTest( "Programmatic DOM", replacementIntValue, value2 ); - - exit(0); - doc->Print(); { @@ -1958,11 +1954,9 @@ int main( int argc, const char ** argv ) XMLDocument doc; for( int i = 0; i < XML_ERROR_COUNT; i++ ) { const XMLError error = static_cast(i); - doc.SetError( error, 0, 0, 0 ); - XMLTest( "ErrorID() after SetError()", error, doc.ErrorID() ); - const char* name = doc.ErrorName(); - XMLTest( "ErrorName() after SetError()", true, name != 0 ); - XMLTest( "ErrorName() after SetError()", true, strlen(name) > 0 ); + const char* name = XMLDocument::ErrorIDToName(error); + XMLTest( "ErrorName() after ClearError()", true, name != 0 ); + XMLTest( "ErrorName() after ClearError()", true, strlen(name) > 0 ); } } @@ -2060,7 +2054,7 @@ int main( int argc, const char ** argv ) XMLTest(testString, parseError, doc.ErrorID()); XMLTest(testString, true, doc.Error()); XMLTest(testString, expected_error, parseError); - XMLTest(testString, expectedLine, doc.GetErrorLineNum()); + XMLTest(testString, expectedLine, doc.ErrorLineNum()); }; void TestStringLines(const char *testString, const char *docStr, const char *expectedLines) @@ -2178,6 +2172,18 @@ int main( int argc, const char ** argv ) "D01L01E02E03A03A03T03E04A04A04T04E05A05A05T05E06A06A06T06E07A07A07T07E08A08A08T08E09T09E10T10"); } + { + const char* xml = "Text"; + XMLDocument doc; + doc.Parse(xml); + XMLTest("Test mismatched elements.", true, doc.Error()); + XMLTest("Test mismatched elements.", XML_ERROR_MISMATCHED_ELEMENT, doc.ErrorID()); + // For now just make sure calls work & doesn't crash. + // May solidify the error output in the future. + printf("%s\n", doc.ErrorStr()); + doc.PrintError(); + } + // ----------- Performance tracking -------------- { #if defined( _MSC_VER ) From 0c0f98bf842ac429eb8c4f19ff093a27e8e11492 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Wed, 11 Oct 2017 11:03:49 -0700 Subject: [PATCH 4/5] merge from master --- tinyxml2.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 5de92b5..9f7ba6f 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2002,8 +2002,7 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : _processEntities( processEntities ), _errorID(XML_SUCCESS), _whitespaceMode( whitespaceMode ), - _errorStr1(), - _errorStr2(), + _errorStr(), _errorLineNum( 0 ), _charBuffer( 0 ), _parseCurLineNum( 0 ), From eb2f51e63bd87a7bb442bcde5eeca68a866b089b Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Wed, 1 Nov 2017 07:52:43 -0700 Subject: [PATCH 5/5] removed unused variables --- tinyxml2.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 9f7ba6f..4fd9998 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1132,7 +1132,6 @@ const XMLElement* XMLNode::ToElementWithName( const char* name ) const // --------- XMLText ---------- // char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { - const char* start = p; if ( this->CData() ) { p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { @@ -1199,7 +1198,6 @@ XMLComment::~XMLComment() char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Comment parses as text. - const char* start = p; p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr ); if ( p == 0 ) { _document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 ); @@ -1249,7 +1247,6 @@ XMLDeclaration::~XMLDeclaration() char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Declaration parses as text. - const char* start = p; p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( p == 0 ) { _document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 ); @@ -1298,8 +1295,6 @@ XMLUnknown::~XMLUnknown() char* XMLUnknown::ParseDeep( char* p, StrPair*, int* curLineNumPtr ) { // Unknown parses as text. - const char* start = p; - p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr ); if ( !p ) { _document->SetError( XML_ERROR_PARSING_UNKNOWN, _parseLineNum, 0 ); @@ -1805,7 +1800,6 @@ void XMLElement::DeleteAttribute( const char* name ) char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr ) { - const char* start = p; XMLAttribute* prevAttribute = 0; // Read the attributes. @@ -2319,7 +2313,7 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ... va_list va; va_start( va, format ); - int result = TIXML_VSNPRINTF( buffer + len, BUFFER_SIZE - len, format, va ); + TIXML_VSNPRINTF( buffer + len, BUFFER_SIZE - len, format, va ); va_end( va ); _errorStr.SetStr(buffer);