Fixed #4389 (False positive: Possible null pointer dereference if the default parameter value is used)
This commit is contained in:
parent
6bd7463c54
commit
309edbbdc5
|
@ -1223,7 +1223,12 @@ void CheckNullPointer::nullPointerDefaultArgument()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dependsOnPointer && Token::simpleMatch(endOfCondition, ") {")) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1232,7 +1237,7 @@ void CheckNullPointer::nullPointerDefaultArgument()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If a pointer is assigned a new value, stop considering it.
|
// 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());
|
pointerArgs.erase(tok->varId());
|
||||||
|
|
||||||
if (isPointerDeRef(tok, unknown, symbolDatabase))
|
if (isPointerDeRef(tok, unknown, symbolDatabase))
|
||||||
|
|
|
@ -2193,6 +2193,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
check("void f(int *p = 0) {\n"
|
||||||
" if (a != 0)\n"
|
" if (a != 0)\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue