Fixed #5434 (FP: Out-of-bounds access with ternary operator in loop)
This commit is contained in:
parent
34730f623a
commit
f6b42633e8
|
@ -665,6 +665,19 @@ static void valueFlowForLoop(TokenList *tokenlist, ErrorLogger *errorLogger, con
|
||||||
|
|
||||||
for (Token *tok2 = bodyStart->next(); tok2 != bodyEnd; tok2 = tok2->next()) {
|
for (Token *tok2 = bodyStart->next(); tok2 != bodyEnd; tok2 = tok2->next()) {
|
||||||
if (tok2->varId() == vartok->varId()) {
|
if (tok2->varId() == vartok->varId()) {
|
||||||
|
const Token * parent = tok2->astParent();
|
||||||
|
while (parent) {
|
||||||
|
const Token * const p = parent;
|
||||||
|
parent = parent->astParent();
|
||||||
|
if (parent && parent->str() == "?" && parent->astOperand2() == p)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (parent) {
|
||||||
|
if (settings->debugwarnings)
|
||||||
|
bailout(tokenlist, errorLogger, tok2, "For loop variable " + vartok->str() + " stopping on ?");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ValueFlow::Value value1(num1);
|
ValueFlow::Value value1(num1);
|
||||||
value1.varId = tok2->varId();
|
value1.varId = tok2->varId();
|
||||||
setTokenValue(tok2, value1);
|
setTokenValue(tok2, value1);
|
||||||
|
|
|
@ -624,6 +624,15 @@ private:
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" for (int x = 0; x < 10; x++)\n"
|
||||||
|
" x<4 ?\n"
|
||||||
|
" a[x] : 0;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 9));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowSubFunction() {
|
void valueFlowSubFunction() {
|
||||||
|
|
Loading…
Reference in New Issue