From db27ad3ef529f9e6b000818ead3a28880b318402 Mon Sep 17 00:00:00 2001 From: Lothar Braun Date: Thu, 30 Apr 2020 14:15:09 +0200 Subject: [PATCH] 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. --- src/core/Cfg.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/Cfg.cpp b/src/core/Cfg.cpp index a205422..99a93a7 100644 --- a/src/core/Cfg.cpp +++ b/src/core/Cfg.cpp @@ -174,6 +174,8 @@ std::vector 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()); }