null pointers: fixed false positives when checking if pointer is null at many locations (#485)
This commit is contained in:
parent
06c8ff9d0d
commit
5b81c92a14
|
@ -1042,6 +1042,21 @@ void CheckOther::nullPointer()
|
|||
if (varid1 == 0)
|
||||
continue;
|
||||
|
||||
// Checking if the struct pointer is non-null before the assignment..
|
||||
{
|
||||
const Token *tok2 = _tokenizer->tokens();
|
||||
while (tok2)
|
||||
{
|
||||
if (tok2 == tok1)
|
||||
break;
|
||||
if (Token::Match(tok2, "if|while ( !| %varid% )", varid1))
|
||||
break;
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
if (tok2 != tok1)
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int indentlevel2 = 0;
|
||||
for (const Token *tok2 = tok1->tokAt(3); tok2; tok2 = tok2->next())
|
||||
{
|
||||
|
|
|
@ -508,6 +508,18 @@ private:
|
|||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// while..
|
||||
checkNullPointer("void freeAbc(struct ABC *abc)\n"
|
||||
"{\n"
|
||||
" while (abc)\n"
|
||||
" {\n"
|
||||
" struct ABC *next = abc->next;\n"
|
||||
" if (abc) delete abc;\n"
|
||||
" abc = next;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// Dereferencing a pointer and then checking if it is null
|
||||
|
|
Loading…
Reference in New Issue