From 189198f19c089b80a73e22299ae023879e9b323e Mon Sep 17 00:00:00 2001 From: Ant Mitchell Date: Tue, 24 Mar 2015 16:20:36 +0000 Subject: [PATCH] Issue 302: clear any previous save error --- tinyxml2.cpp | 3 +++ xmltest.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 57a4840..f8683aa 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1879,6 +1879,9 @@ XMLError XMLDocument::SaveFile( const char* filename, bool compact ) XMLError XMLDocument::SaveFile( FILE* fp, bool compact ) { + // Clear any error from the last save, otherwise it will get reported + // for *this* call. + SetError( XML_NO_ERROR, 0, 0 ); XMLPrinter stream( fp, compact ); Print( &stream ); return _errorID; diff --git a/xmltest.cpp b/xmltest.cpp index 243628c..09c781e 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1425,6 +1425,15 @@ int main( int argc, const char ** argv ) XMLPrinter printer; doc.Print( &printer ); } + { + // Issue 302. Clear errors from LoadFile/SaveFile + XMLDocument doc; + doc.SaveFile( "./no/such/path/pretty.xml" ); + XMLTest( "Issue 302. Fail to save", doc.ErrorName(), "XML_ERROR_FILE_COULD_NOT_BE_OPENED" ); + doc.SaveFile( "./resources/out/compact.xml", true ); + XMLTest( "Issue 302. Subsequent success in saving", doc.ErrorName(), "XML_SUCCESS" ); + + } // ----------- Performance tracking -------------- {