value flow: improved handling of loops
This commit is contained in:
parent
498cdb8610
commit
c7032a8867
|
@ -276,7 +276,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
// if variable is assigned in loop don't look before the loop
|
||||
if (tok2->previous() &&
|
||||
(Token::Match(tok2->previous(), "do") ||
|
||||
(tok2->str() == ")" && Token::Match(tok2->linkAt(-1)->previous(), "for|while (")))) {
|
||||
(tok2->strAt(-1) == ")" && Token::Match(tok2->linkAt(-1)->previous(), "for|while (")))) {
|
||||
|
||||
const Token *start = tok2;
|
||||
const Token *end = start->link();
|
||||
|
|
|
@ -240,6 +240,15 @@ private:
|
|||
" } while (1);\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 2U, 76));
|
||||
|
||||
code = "void f(X x) {\n" // conditions inside loop, x is assigned inside do-while => dont use condition
|
||||
" a = x;\n"
|
||||
" for (i=1;i<=count;i++) {\n"
|
||||
" BUGON(x==0)\n"
|
||||
" x = x.next;\n"
|
||||
" }\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 2U, 0));
|
||||
}
|
||||
|
||||
void valueFlowBeforeConditionTernaryOp() { // bailout: ?:
|
||||
|
|
Loading…
Reference in New Issue