Null pointer: better handling when calling standard functions with possible null pointer
This commit is contained in:
parent
afc825da68
commit
cc89687e8c
|
@ -715,6 +715,21 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
continue;
|
||||
}
|
||||
|
||||
// function call, check if pointer is dereferenced
|
||||
if (Token::Match(tok2, "%var% ("))
|
||||
{
|
||||
std::list<const Token *> var;
|
||||
parseFunctionCall(*tok2, var, 0);
|
||||
for (std::list<const Token *>::const_iterator it = var.begin(); it != var.end(); ++it)
|
||||
{
|
||||
if ((*it)->varId() == varid)
|
||||
{
|
||||
nullPointerError(*it, pointerName, linenr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// calling unknown function (abort/init)..
|
||||
if (Token::simpleMatch(tok2, ") ;") &&
|
||||
(Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% (") ||
|
||||
|
|
|
@ -985,6 +985,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (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"
|
||||
" strcpy(p, \"abc\");\n"
|
||||
"}\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(abc *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" }\n"
|
||||
|
|
Loading…
Reference in New Issue