fix another false negative introduced by fix for #2641

This commit is contained in:
Robert Reif 2011-03-12 12:27:19 -05:00
parent 384bd96766
commit 6a2848e50f
2 changed files with 9 additions and 1 deletions

View File

@ -415,7 +415,7 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
// is pointer local? // is pointer local?
bool isLocal = false; bool isLocal = false;
const Variable * var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok1->varId()); const Variable * var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(tok1->varId());
if (var && var->isLocal()) if (var && (var->isLocal() || var->isArgument()))
isLocal = true; isLocal = true;
// count { and } using tok2 // count { and } using tok2

View File

@ -344,6 +344,14 @@ private:
" if (abc) { }\n" " 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()); 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 // Dereferencing a pointer and then checking if it is null