Fixed #6710 (valueFlowBeforeCondition: function call in loop seems to cause FN)

This commit is contained in:
Daniel Marjamäki 2015-05-27 20:25:58 +02:00
parent 0bd7cbfbeb
commit 152ea116fa
2 changed files with 10 additions and 7 deletions

View File

@ -697,7 +697,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo
const Token *vartok = Token::findmatch(tok2->link(), "%varid%", tok2, varid); const Token *vartok = Token::findmatch(tok2->link(), "%varid%", tok2, varid);
while (Token::Match(vartok, "%name% = %num% ;") && !vartok->tokAt(2)->getValue(num)) while (Token::Match(vartok, "%name% = %num% ;") && !vartok->tokAt(2)->getValue(num))
vartok = Token::findmatch(vartok->next(), "%varid%", tok2, varid); vartok = Token::findmatch(vartok->next(), "%varid%", tok2, varid);
if (vartok) { if (isVariableChanged(tok2->link(), tok2, varid) && vartok) {
if (settings->debugwarnings) { if (settings->debugwarnings) {
std::string errmsg = "variable "; std::string errmsg = "variable ";
if (var) if (var)

View File

@ -522,18 +522,21 @@ private:
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0)); ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
bailout("void f(int x) {\n"
" if (x != 123) { b = x; }\n"
" if (x == 123) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on }\n", errout.str());
code = "void f(int x) {\n" code = "void f(int x) {\n"
" a = x;\n" " a = x;\n"
" if (abc) { x = 1; }\n" // <- condition must be false if x is 7 in next line " if (abc) { x = 1; }\n" // <- condition must be false if x is 7 in next line
" if (x == 7) { }\n" " if (x == 7) { }\n"
"}"; "}";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 7)); ASSERT_EQUALS(true, testValueOfX(code, 2U, 7));
code = "void dostuff(const int *x);\n" // #6710
"void f(const int *x) {\n"
" for (int i = *x; i > 0; --i) {\n"
" dostuff(x);\n"
" }\n"
" if (x) {}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
} }
void valueFlowBeforeConditionGlobalVariables() { void valueFlowBeforeConditionGlobalVariables() {