From 1cfafd0d244a4b19037b5173efe4cb4af810806a Mon Sep 17 00:00:00 2001 From: Vasily Biryukov Date: Sat, 20 Apr 2013 14:12:33 +0600 Subject: [PATCH] Fixed: LoadFile() returns XML_NO_ERROR for empty documents. --- resources/empty.xml | 0 tinyxml2.cpp | 1 + xmltest.cpp | 7 +++++++ 3 files changed, 8 insertions(+) create mode 100644 resources/empty.xml diff --git a/resources/empty.xml b/resources/empty.xml new file mode 100644 index 0000000..e69de29 diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 1b9a419..3b38584 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1608,6 +1608,7 @@ XMLError XMLDocument::LoadFile( FILE* fp ) fseek( fp, 0, SEEK_SET ); if ( size == 0 ) { + SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } diff --git a/xmltest.cpp b/xmltest.cpp index 2e056d1..231328e 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1158,6 +1158,13 @@ int main( int argc, const char ** argv ) } + { + XMLDocument doc; + XMLError error = doc.LoadFile( "resources/empty.xml" ); + XMLTest( "Loading an empty file", XML_ERROR_EMPTY_DOCUMENT, error ); + } + + // ----------- Performance tracking -------------- { #if defined( _MSC_VER )