Fixed #1629 (False negative: null pointer derefence not detected 'c[0] = 0')

This commit is contained in:
Daniel Marjamäki 2010-04-28 22:07:39 +02:00
parent 2666aad207
commit cccccff96f
2 changed files with 20 additions and 1 deletions

View File

@ -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;
}

View File

@ -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"