Skip to content

Commit 8fe7ee1

Browse files
committed
Fixed #7886 (ValueFlow: endless forloop 'for (i = 0, j = 0; i < sz && j < 9; i++)')
1 parent a8788d7 commit 8fe7ee1

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2859,12 +2859,12 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
28592859
valueFlowFunctionReturn(tokenlist, errorLogger);
28602860
valueFlowBitAnd(tokenlist);
28612861
valueFlowOppositeCondition(symboldatabase, settings);
2862-
valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings);
28632862
valueFlowBeforeCondition(tokenlist, symboldatabase, errorLogger, settings);
28642863
valueFlowAfterMove(tokenlist, symboldatabase, errorLogger, settings);
28652864
valueFlowAfterAssign(tokenlist, symboldatabase, errorLogger, settings);
28662865
valueFlowAfterCondition(tokenlist, symboldatabase, errorLogger, settings);
28672866
valueFlowSwitchVariable(tokenlist, symboldatabase, errorLogger, settings);
2867+
valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings);
28682868
valueFlowSubFunction(tokenlist, errorLogger, settings);
28692869
valueFlowFunctionDefaultParameter(tokenlist, symboldatabase, errorLogger, settings);
28702870
}

test/testvalueflow.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,6 @@ class TestValueFlow : public TestFixture {
18471847
"}\n";
18481848
ASSERT_EQUALS(false, testValueOfX(code, 9U, 11));
18491849

1850-
18511850
// hang
18521851
code = "void f() {\n"
18531852
" for(int i = 0; i < 20; i++)\n"
@@ -1867,6 +1866,14 @@ class TestValueFlow : public TestFixture {
18671866
"}";
18681867
ASSERT_EQUALS(false, testValueOfX(code, 6U, 10));
18691868

1869+
// #7886 - valueFlowForLoop must be called after valueFlowAfterAssign
1870+
code = "void f() {\n"
1871+
" int sz = 4;\n"
1872+
" int x,y;\n"
1873+
" for(x=0,y=0; x < sz && y < 10; x++)\n"
1874+
" a = x;\n" // <- max value is 3
1875+
"}";
1876+
ASSERT_EQUALS(true, testValueOfX(code, 5U, 3));
18701877
}
18711878

18721879
void valueFlowSubFunction() {

0 commit comments

Comments
 (0)