Skip to content

Commit 152ea11

Browse files
committed
Fixed danmar#6710 (valueFlowBeforeCondition: function call in loop seems to cause FN)
1 parent 0bd7cbf commit 152ea11

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo
697697
const Token *vartok = Token::findmatch(tok2->link(), "%varid%", tok2, varid);
698698
while (Token::Match(vartok, "%name% = %num% ;") && !vartok->tokAt(2)->getValue(num))
699699
vartok = Token::findmatch(vartok->next(), "%varid%", tok2, varid);
700-
if (vartok) {
700+
if (isVariableChanged(tok2->link(), tok2, varid) && vartok) {
701701
if (settings->debugwarnings) {
702702
std::string errmsg = "variable ";
703703
if (var)

test/testvalueflow.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,21 @@ class TestValueFlow : public TestFixture {
522522
ASSERT_EQUALS(false, testValueOfX(code, 4U, 0));
523523
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
524524

525-
bailout("void f(int x) {\n"
526-
" if (x != 123) { b = x; }\n"
527-
" if (x == 123) {}\n"
528-
"}");
529-
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on }\n", errout.str());
530-
531525
code = "void f(int x) {\n"
532526
" a = x;\n"
533527
" if (abc) { x = 1; }\n" // <- condition must be false if x is 7 in next line
534528
" if (x == 7) { }\n"
535529
"}";
536530
ASSERT_EQUALS(true, testValueOfX(code, 2U, 7));
531+
532+
code = "void dostuff(const int *x);\n" // #6710
533+
"void f(const int *x) {\n"
534+
" for (int i = *x; i > 0; --i) {\n"
535+
" dostuff(x);\n"
536+
" }\n"
537+
" if (x) {}\n"
538+
"}";
539+
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
537540
}
538541

539542
void valueFlowBeforeConditionGlobalVariables() {

0 commit comments

Comments
 (0)