From b31f4bfe549372cfab7852c27ce22afa0e949bad Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 1 Jul 2024 23:44:13 +0200 Subject: [PATCH] Partial fix for #11567 FN nullPointer/ctunullpointer with default parameter (regression) --- lib/valueflow.cpp | 2 +- test/testnullpointer.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 0bd0b70d16f..6276ac1c227 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6946,7 +6946,7 @@ static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const continue; for (std::size_t arg = function->minArgCount(); arg < function->argCount(); arg++) { const Variable* var = function->getArgumentVar(arg); - if (var && var->hasDefault() && Token::Match(var->nameToken(), "%var% = %num%|%str% [,)]")) { + if (var && var->hasDefault() && Token::Match(var->nameToken(), "%var% = %num%|%str%|%char%|%name% [,)]")) { const std::list &values = var->nameToken()->tokAt(2)->values(); std::list argvalues; for (const ValueFlow::Value &value : values) { diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index a9a2a82043d..6a026119d30 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4405,6 +4405,10 @@ class TestNullPointer : public TestFixture { " int var1 = x ? *p : 5;\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible null pointer dereference if the default parameter value is used: p\n", errout_str()); + + check("void f(int* i = nullptr) { *i = 0; }\n" // #11567 + "void g() { f(); }\n"); + ASSERT_EQUALS("[test.cpp:1]: (warning) Possible null pointer dereference if the default parameter value is used: i\n", errout_str()); } void nullpointer_internal_error() { // ticket #5080