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:
parent
80a6d7c390
commit
4b1544d33b
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue