Fix #11561 FN nullPointer with unnamed parameter (#4805)

This commit is contained in:
chrchr-github 2023-02-23 22:56:03 +01:00 committed by GitHub
parent edc9cfba94
commit 96887c8130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -7529,7 +7529,7 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg
ProgramMemory programMemory;
for (std::size_t i = 0; i < parvalues.size(); ++i) {
const Variable * const arg = function->getArgumentVar(i);
if (!arg || !Token::Match(arg->typeStartToken(), "%type% %name% ,|)")) {
if (!arg) {
if (tokenlist->getSettings()->debugwarnings)
bailout(tokenlist, errorLogger, tok, "function return; unhandled argument type");
programMemory.clear();

View File

@ -3707,6 +3707,11 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: p\n"
"[test.cpp:4]: (error) Null pointer dereference\n",
errout.str());
check("const char* g(long) { return nullptr; }\n" // #11561
"void f() { std::string s = g(0L); }\n");
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: g(0L)\n",
errout.str());
}
void nullpointerStdStream() {