Fixed #5656 (false positive: (error) Possible null pointer dereference: f)

This commit is contained in:
Daniel Marjamäki 2014-04-18 16:10:18 +02:00
parent cf12f2aaac
commit 56eb717b8a
2 changed files with 10 additions and 1 deletions

View File

@ -523,7 +523,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
Token * const end = start->link();
if (Token::findmatch(start, "%varid%", end, varid)) {
// TODO: don't check noreturn scopes
if (number_of_if > 0U) {
if (number_of_if > 0U || Token::findmatch(tok2, "%varid%", start, varid)) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " is assigned in conditional code");
break;

View File

@ -594,6 +594,15 @@ private:
"}";
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 4U, 32));
code = "void f() {\n" // #5656 - FP
" int x = 0;\n"
" if (!x) {\n"
" x = getx();\n"
" }\n"
" y = x;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 6U, 0));
// multivariables
code = "void f(int a) {\n"
" int x = a;\n"