From a6cc9b22d89d87b5f3bed64911a8f6cd39abb44e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 2 Jul 2024 21:44:20 +0200 Subject: [PATCH] Partial fix for #11567 FN nullPointer/ctunullpointer with default parameter (regression) (#6565) --- 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 80b451a7055..80ea644c781 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6941,7 +6941,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