Fixed #1726 (False negative: null pointer dereference in switch block)
This commit is contained in:
parent
e140ff6e84
commit
472bd9dabe
|
@ -2488,6 +2488,14 @@ private:
|
||||||
/** parse condition. @sa ExecutionPath::parseCondition */
|
/** parse condition. @sa ExecutionPath::parseCondition */
|
||||||
bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks)
|
bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks)
|
||||||
{
|
{
|
||||||
|
for (const Token *tok2 = &tok; tok2; tok2 = tok2->next())
|
||||||
|
{
|
||||||
|
if (tok2->str() == "(" || tok2->str() == ")")
|
||||||
|
break;
|
||||||
|
if (Token::Match(tok2, "[<>=] * %var%"))
|
||||||
|
dereference(checks, tok2->tokAt(2));
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(&tok, "!| %var% ("))
|
if (Token::Match(&tok, "!| %var% ("))
|
||||||
{
|
{
|
||||||
std::list<const Token *> var;
|
std::list<const Token *> var;
|
||||||
|
|
|
@ -1041,6 +1041,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str());
|
||||||
|
|
||||||
|
checkNullPointer("static void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" int *p = 0;\n"
|
||||||
|
" if (3 > *p);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
checkNullPointer("void f()\n"
|
checkNullPointer("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x) {\n"
|
" if (x) {\n"
|
||||||
|
|
Loading…
Reference in New Issue