From 4b1544d33b5e401657d9b5ed94550ab7907aa359 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 18 Jan 2019 17:10:41 +0100 Subject: [PATCH] library.cpp: Let tinyxml2 print a helpful error message when XML is bad (#1609) In case the XML code of a library configuration is invalid Cppcheck now additionally prints out some helpful error description like this: "Error=XML_ERROR_MISMATCHED_ELEMENT ErrorID=16 (0x10) Line number=304: XMLElement name=noreturn" --- lib/library.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 6284939a7..f8c97a842 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -127,7 +127,12 @@ Library::Error Library::load(const char exename[], const char path[]) return Error(OK); // ignore duplicates } - return Error(error == tinyxml2::XML_ERROR_FILE_NOT_FOUND ? FILE_NOT_FOUND : BAD_XML); + if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) + return Error(FILE_NOT_FOUND); + else { + doc.PrintError(); + return Error(BAD_XML); + } } bool Library::loadxmldata(const char xmldata[], std::size_t len) @@ -140,8 +145,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) { const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement(); - if (rootnode == nullptr) + if (rootnode == nullptr) { + doc.PrintError(); return Error(BAD_XML); + } if (strcmp(rootnode->Name(),"def") != 0) return Error(UNSUPPORTED_FORMAT, rootnode->Name());