library.cpp: WarnInfo: Fix crash (#1697)

If no 'alternatives' argument was specified and the `<warn/>` 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.
This commit is contained in:
Sebastian 2019-02-28 06:19:42 +01:00 committed by GitHub
parent 11daabc1a8
commit c8a7a4c653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -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