Fixed #4389 (False positive: Possible null pointer dereference if the default parameter value is used)

This commit is contained in:
Zachary Blair 2013-01-09 23:22:54 -08:00
parent 6bd7463c54
commit 309edbbdc5
2 changed files with 15 additions and 2 deletions

View File

@ -1223,7 +1223,12 @@ void CheckNullPointer::nullPointerDefaultArgument()
}
}
if (dependsOnPointer && Token::simpleMatch(endOfCondition, ") {")) {
tok = endOfCondition->next()->link();
const Token *endOfIf = endOfCondition->next()->link();
for (; tok != endOfIf; tok = tok->next()) {
// If a pointer is assigned a new value, stop considering it.
if (Token::Match(tok, "%var% ="))
pointerArgs.erase(tok->varId());
}
continue;
}
}
@ -1232,7 +1237,7 @@ void CheckNullPointer::nullPointerDefaultArgument()
continue;
// If a pointer is assigned a new value, stop considering it.
if (Token::Match(tok, "%var% = %any%"))
if (Token::Match(tok, "%var% ="))
pointerArgs.erase(tok->varId());
if (isPointerDeRef(tok, unknown, symbolDatabase))

View File

@ -2193,6 +2193,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void f(int *p = 0) {\n"
" int y;\n"
" if (p == 0)\n"
" p = &y;\n"
" *p = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(int *p = 0) {\n"
" if (a != 0)\n"
" *p = 0;\n"