Fixed #1629 (False negative: null pointer derefence not detected 'c[0] = 0')
This commit is contained in:
parent
2666aad207
commit
cccccff96f
|
@ -1782,7 +1782,7 @@ private:
|
|||
bailOutVar(checks, tok.varId());
|
||||
}
|
||||
|
||||
if (Token::simpleMatch(&tok, "* 0"))
|
||||
else if (Token::simpleMatch(&tok, "* 0"))
|
||||
{
|
||||
if (Token::Match(tok.previous(), "[;{}=+-/(,]") ||
|
||||
Token::Match(tok.previous(), "return|<<"))
|
||||
|
@ -1795,6 +1795,15 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
else if (tok.str() == "delete")
|
||||
{
|
||||
const Token *ret = tok.next();
|
||||
if (Token::simpleMatch(ret, "[ ]"))
|
||||
ret = ret->tokAt(2);
|
||||
if (Token::Match(ret, "%var% ;"))
|
||||
return ret->next();
|
||||
}
|
||||
|
||||
return &tok;
|
||||
}
|
||||
|
||||
|
|
|
@ -1020,6 +1020,16 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
|
||||
|
||||
checkNullPointer("void f()\n"
|
||||
"{\n"
|
||||
" char *c = 0;\n"
|
||||
" {\n"
|
||||
" delete c;\n"
|
||||
" }\n"
|
||||
" c[0] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str());
|
||||
|
||||
// no false positive..
|
||||
checkNullPointer("static void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue