Skip to content

Commit 1ab5805

Browse files
committed
Fixed #6616 (valueFlowForward: for loop, variable in 3rd expression is changed in loop body)
1 parent ec9facb commit 1ab5805

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ static bool valueFlowForward(Token * const startToken,
11601160
if (tok3->varId() == varid) {
11611161
for (std::list<ValueFlow::Value>::const_iterator it = values.begin(); it != values.end(); ++it)
11621162
setTokenValue(tok3, *it);
1163-
} else if (Token::Match(tok3, "%oror%|&&|?")) {
1163+
} else if (Token::Match(tok3, "%oror%|&&|?|;")) {
11641164
break;
11651165
}
11661166
}
@@ -1229,7 +1229,7 @@ static bool valueFlowForward(Token * const startToken,
12291229
for (it = values.begin(); it != values.end(); ++it)
12301230
setTokenValue(condtok, *it);
12311231
}
1232-
if (Token::Match(condtok, "%oror%|&&"))
1232+
if (Token::Match(condtok, "%oror%|&&|?|;"))
12331233
break;
12341234
}
12351235
if (settings->debugwarnings)

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,14 @@ class TestValueFlow : public TestFixture {
11761176
" a = x;\n" // <- x can be 0
11771177
"}\n";
11781178
ASSERT_EQUALS(true, testValueOfX(code, 9U, 0)); // x can be 0 at line 9
1179+
1180+
code = "void f(const int a[]) {\n" // #6616
1181+
" const int *x = 0;\n"
1182+
" for (int i = 0; i < 10; i = *x) {\n" // <- x is not 0
1183+
" x = a[i];\n"
1184+
" }\n"
1185+
"}\n";
1186+
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
11791187
}
11801188

11811189
void valueFlowAfterCondition() {

0 commit comments

Comments
 (0)