Fixed #3394 (False positive: possible null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2011-12-08 19:30:14 +01:00
parent 1bef8d1247
commit e2dd085b60
2 changed files with 13 additions and 1 deletions

View File

@ -484,7 +484,7 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
// dereference in assignment
else if (Token::Match(tok1, "[{};] %var% = %var% . %var%")) {
if (std::string(tok1->strAt(1)) == tok1->strAt(3))
if (tok1->strAt(1) == tok1->strAt(3))
continue;
tok1 = tok1->tokAt(3);
}
@ -716,6 +716,12 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
if (Token::Match(tok1->tokAt(-2), "%varid% = %varid% .", varid)) {
break;
} else if (Token::simpleMatch(tok1->tokAt(-2), "* )") &&
Token::Match(tok1->linkAt(-1)->tokAt(-2), "%varid% = (", tok1->varId())) {
break;
} else if (Token::simpleMatch(tok1->tokAt(-3), "* ) (") &&
Token::Match(tok1->linkAt(-2)->tokAt(-2), "%varid% = (", tok1->varId())) {
break;
} else if (Token::Match(tok1->previous(), "&&|%oror%")) {
break;
} else if (Token::Match(tok1->tokAt(-2), "&&|%oror% !")) {

View File

@ -316,6 +316,12 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(struct ABC *abc) {\n"
" abc = (ABC *)(abc->_next);\n"
" if (abc) { }"
"}\n");
ASSERT_EQUALS("", errout.str());
// reassign struct..
check("void foo(struct ABC *abc)\n"
"{\n"