Skip to content

Commit 96887c8

Browse files
Fix #11561 FN nullPointer with unnamed parameter (#4805)
1 parent edc9cfb commit 96887c8

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7529,7 +7529,7 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg
75297529
ProgramMemory programMemory;
75307530
for (std::size_t i = 0; i < parvalues.size(); ++i) {
75317531
const Variable * const arg = function->getArgumentVar(i);
7532-
if (!arg || !Token::Match(arg->typeStartToken(), "%type% %name% ,|)")) {
7532+
if (!arg) {
75337533
if (tokenlist->getSettings()->debugwarnings)
75347534
bailout(tokenlist, errorLogger, tok, "function return; unhandled argument type");
75357535
programMemory.clear();

test/testnullpointer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,11 @@ class TestNullPointer : public TestFixture {
37073707
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference: p\n"
37083708
"[test.cpp:4]: (error) Null pointer dereference\n",
37093709
errout.str());
3710+
3711+
check("const char* g(long) { return nullptr; }\n" // #11561
3712+
"void f() { std::string s = g(0L); }\n");
3713+
ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference: g(0L)\n",
3714+
errout.str());
37103715
}
37113716

37123717
void nullpointerStdStream() {

0 commit comments

Comments
 (0)