Skip to content

Commit

Permalink
Partial fix for #11567 FN nullPointer/ctunullpointer with default par…
Browse files Browse the repository at this point in the history
…ameter (regression)
  • Loading branch information
chrchr-github committed Jul 1, 2024
1 parent a8ee10a commit b31f4bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValueFlow::Value> &values = var->nameToken()->tokAt(2)->values();
std::list<ValueFlow::Value> argvalues;
for (const ValueFlow::Value &value : values) {
Expand Down
4 changes: 4 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b31f4bf

Please sign in to comment.