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"
This commit is contained in:
Sebastian 2019-01-18 17:10:41 +01:00 committed by GitHub
parent 80a6d7c390
commit 4b1544d33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -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());