diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index c5c9ac0b5..a58297c58 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -415,7 +415,7 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec() // is pointer local? bool isLocal = false; const Variable * var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok1->varId()); - if (var && var->isLocal()) + if (var && (var->isLocal() || var->isArgument())) isLocal = true; // count { and } using tok2 diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index d8507c968..2b84036d5 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -344,6 +344,14 @@ private: " if (abc) { }\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 5\n",errout.str()); + + // #2641 - local pointer, function call + check("void f(ABC *abc) {\n" + " abc->a = 0;\n" + " do_stuff();\n" + " if (abc) { }\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 4\n",errout.str()); } // Dereferencing a pointer and then checking if it is null