Throw exception on missing "id" field in configuration

The debug build asserts on the id field, but the release does
not have a check for an missing ID field in the configuration.
This commit introduces a check that is also performed in the
release build to avoid a null ptr dereference in broken config
files.
master
Lothar Braun 2020-04-30 14:15:09 +02:00
parent 8cc87025ff
commit db27ad3ef5
1 changed files with 3 additions and 1 deletions

View File

@ -174,6 +174,8 @@ std::vector<unsigned int> Cfg::getNext()
unsigned int Cfg::getID()
{
XMLAttribute* attr = _elem->getAttribute("id");
assert(attr != NULL);
if (attr == NULL) {
THROWEXCEPTION("Error: Configuration Element '%s' does not have an 'id' field. 'id' is required!", _elem->getName().c_str());
}
return atoi(attr->getValue().c_str());
}