From 6a2848e50f05c73f7e0dd413ff3be56078f969eb Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 12 Mar 2011 12:27:19 -0500 Subject: [PATCH] fix another false negative introduced by fix for #2641 --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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