Fixed #6616 (valueFlowForward: for loop, variable in 3rd expression is changed in loop body)

This commit is contained in:
Daniel Marjamäki 2016-02-08 10:43:41 +01:00
parent ec9facb701
commit 1ab5805d98
2 changed files with 10 additions and 2 deletions

View File

@ -1160,7 +1160,7 @@ static bool valueFlowForward(Token * const startToken,
if (tok3->varId() == varid) {
for (std::list<ValueFlow::Value>::const_iterator it = values.begin(); it != values.end(); ++it)
setTokenValue(tok3, *it);
} else if (Token::Match(tok3, "%oror%|&&|?")) {
} else if (Token::Match(tok3, "%oror%|&&|?|;")) {
break;
}
}
@ -1229,7 +1229,7 @@ static bool valueFlowForward(Token * const startToken,
for (it = values.begin(); it != values.end(); ++it)
setTokenValue(condtok, *it);
}
if (Token::Match(condtok, "%oror%|&&"))
if (Token::Match(condtok, "%oror%|&&|?|;"))
break;
}
if (settings->debugwarnings)

View File

@ -1176,6 +1176,14 @@ private:
" a = x;\n" // <- x can be 0
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 9U, 0)); // x can be 0 at line 9
code = "void f(const int a[]) {\n" // #6616
" const int *x = 0;\n"
" for (int i = 0; i < 10; i = *x) {\n" // <- x is not 0
" x = a[i];\n"
" }\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
}
void valueFlowAfterCondition() {