Fixed #6616 (valueFlowForward: for loop, variable in 3rd expression is changed in loop body)
This commit is contained in:
parent
ec9facb701
commit
1ab5805d98
|
@ -1160,7 +1160,7 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
if (tok3->varId() == varid) {
|
if (tok3->varId() == varid) {
|
||||||
for (std::list<ValueFlow::Value>::const_iterator it = values.begin(); it != values.end(); ++it)
|
for (std::list<ValueFlow::Value>::const_iterator it = values.begin(); it != values.end(); ++it)
|
||||||
setTokenValue(tok3, *it);
|
setTokenValue(tok3, *it);
|
||||||
} else if (Token::Match(tok3, "%oror%|&&|?")) {
|
} else if (Token::Match(tok3, "%oror%|&&|?|;")) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1229,7 +1229,7 @@ static bool valueFlowForward(Token * const startToken,
|
||||||
for (it = values.begin(); it != values.end(); ++it)
|
for (it = values.begin(); it != values.end(); ++it)
|
||||||
setTokenValue(condtok, *it);
|
setTokenValue(condtok, *it);
|
||||||
}
|
}
|
||||||
if (Token::Match(condtok, "%oror%|&&"))
|
if (Token::Match(condtok, "%oror%|&&|?|;"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (settings->debugwarnings)
|
if (settings->debugwarnings)
|
||||||
|
|
|
@ -1176,6 +1176,14 @@ private:
|
||||||
" a = x;\n" // <- x can be 0
|
" a = x;\n" // <- x can be 0
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 9U, 0)); // x can be 0 at line 9
|
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() {
|
void valueFlowAfterCondition() {
|
||||||
|
|
Loading…
Reference in New Issue