Fixed #1442 (false positive: getting offset instead of dereferencing a null pointer)

This commit is contained in:
Daniel Marjamäki 2010-02-22 21:30:21 +01:00
parent dfe18dbb71
commit 0b2ad2164f
2 changed files with 9 additions and 2 deletions

View File

@ -1521,7 +1521,7 @@ private:
dereference(foundError, checks, &tok);
else if (Token::Match(tok.tokAt(-2), "return * %var%"))
dereference(foundError, checks, &tok);
else if (Token::Match(tok.next(), ". %var%"))
else if (!Token::simpleMatch(tok.tokAt(-2), "& (") && Token::Match(tok.next(), ". %var%"))
dereference(foundError, checks, &tok);
else if (Token::Match(tok.previous(), "[;{}=+-/(,] %var% [ %any% ]"))
dereference(foundError, checks, &tok);

View File

@ -1015,6 +1015,13 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkNullPointer("void get_offset(long &offset)\n"
"{\n"
" mystruct * temp; temp = 0;\n"
" offset = (long)(&(temp->z));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// function pointer..
checkNullPointer("void foo()\n"
"{\n"