Fixed #6000 (ValueFlow: conditional code in for loops)

This commit is contained in:
Daniel Marjamäki 2016-01-24 13:11:51 +01:00
parent 76cdfbf487
commit a8416bfb16
2 changed files with 21 additions and 0 deletions

View File

@ -2017,6 +2017,14 @@ static void valueFlowForLoopSimplify(Token * const bodyStart, const unsigned int
tok2 = tok2->linkAt(2); tok2 = tok2->linkAt(2);
} }
} }
else if (Token::simpleMatch(tok2, ") {")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop skipping {} code");
tok2 = tok2->linkAt(1);
if (Token::simpleMatch(tok2, "} else {"))
tok2 = tok2->linkAt(2);
}
} }
} }

View File

@ -1600,6 +1600,19 @@ private:
" n = (int)(i < 10 || abs(negWander) < abs(negTravel));\n" " n = (int)(i < 10 || abs(negWander) < abs(negTravel));\n"
"}"; "}";
testValueOfX(code,0,0); // <- dont hang testValueOfX(code,0,0); // <- dont hang
// conditional code in loop
code = "void f(int mask) {\n" // #6000
" for (int x = 10; x < 14; x++) {\n"
" int bit = mask & (1 << i);\n"
" if (bit) {\n"
" if (bit == (1 << 10)) {}\n"
" else { a = x; }\n" // <- x is not 10
" }\n"
" }\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 6U, 10));
} }
void valueFlowSubFunction() { void valueFlowSubFunction() {