Null pointer: fix false negatives when unknown function is called and pointer is local/argument
This commit is contained in:
parent
cc89687e8c
commit
1640f3d1ca
|
@ -735,7 +735,15 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
(Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% (") ||
|
||||
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) (")))
|
||||
{
|
||||
break;
|
||||
// noreturn function?
|
||||
if (tok2->strAt(2) == "}")
|
||||
break;
|
||||
|
||||
// init function (global variables)
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
const Variable *var = symbolDatabase->getVariableFromVarId(varid);
|
||||
if (!var || !(var->isLocal() || var->isArgument()))
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok2->varId() == varid)
|
||||
|
|
|
@ -992,6 +992,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 2\n", errout.str());
|
||||
|
||||
check("void foo(char *p) {\n"
|
||||
" if (p) {\n"
|
||||
" }\n"
|
||||
" bar();\n"
|
||||
" strcpy(p, \"abc\");\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 2\n", errout.str());
|
||||
|
||||
check("void foo(abc *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" }\n"
|
||||
|
|
Loading…
Reference in New Issue