Fixed #2130 (Invalid possible NULL pointer dereference, etc.)

This commit is contained in:
Daniel Marjamäki 2010-10-26 17:40:30 +02:00
parent bdd6d6d53d
commit 893f7fa347
2 changed files with 16 additions and 0 deletions

View File

@ -2569,6 +2569,13 @@ void CheckOther::nullPointerByCheckAndDeRef()
break; break;
} }
// abort function..
if (Token::Match(tok2->previous(), "[;{}] %var% (") &&
Token::simpleMatch(tok2->next()->link(), ") ; }"))
{
break;
}
if (tok2->varId() == varid) if (tok2->varId() == varid)
{ {
if (Token::Match(tok2->previous(), "[;{}=] %var% = 0 ;")) if (Token::Match(tok2->previous(), "[;{}=] %var% = 0 ;"))

View File

@ -1169,6 +1169,15 @@ private:
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkNullPointer("void foo(char *p) {\n"
" if (!p) {\n"
" abort();\n"
" }\n"
" *p = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void checkUninitVar(const char code[]) void checkUninitVar(const char code[])