From c8a7a4c653761d0785950b2cb00d50b44691d95f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 28 Feb 2019 06:19:42 +0100 Subject: [PATCH] library.cpp: WarnInfo: Fix crash (#1697) If no 'alternatives' argument was specified and the `` element did not contain any text Cppcheck crashed because of a null pointer access. If there is no 'reason' and no 'alternatives argument and also no text loadFunction() returns with an error. --- lib/library.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index e595f0c70..010d808db 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -723,8 +723,13 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co else wi.message += ", "; } - } else - wi.message = functionnode->GetText(); + } else { + const char * const message = functionnode->GetText(); + if (!message) { + return Error(MISSING_ATTRIBUTE, "\"reason\" and \"alternatives\" or some text."); + } else + wi.message = message; + } functionwarn[name] = wi; } else