test1
This commit is contained in:
parent
3e7f692d4d
commit
3eebc8a9f1
|
@ -103,7 +103,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok2->varId() == varid) {
|
if (tok2->varId() == varid) {
|
||||||
// bailout: assignment
|
// bailout: assignment
|
||||||
if (Token::Match(tok2->previous(), "!!* %var% =")) {
|
if (Token::Match(tok2->previous(), "!!* %var% =")) {
|
||||||
|
@ -138,12 +138,12 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
}
|
}
|
||||||
} else if (var->isGlobal() && tok2->str() == "{") {
|
} else if (var->isGlobal() && tok2->str() == "{") {
|
||||||
if (!Token::Match(tok2->previous(), ")|else {"))
|
if (!Token::Match(tok2->previous(), ")|else {"))
|
||||||
break;
|
break;
|
||||||
if (Token::Match(tok2->previous(), ") {") &&
|
if (Token::Match(tok2->previous(), ") {") &&
|
||||||
!Token::Match(tok2->linkAt(-1)->previous(), "if|for|while ("))
|
!Token::Match(tok2->linkAt(-1)->previous(), "if|for|while ("))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,10 +154,20 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowForLoop() {
|
void valueFlowForLoop() {
|
||||||
const char code[] = "void f() {\n"
|
const char *code;
|
||||||
" for (int x = 0; x < 10; x++)\n"
|
|
||||||
" a[x] = 0;\n"
|
code = "void f() {\n"
|
||||||
"}";
|
" for (int x = 0; x < 10; x++)\n"
|
||||||
|
" a[x] = 0;\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 10));
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" for (int x = 0; x < (short)10; x++)\n"
|
||||||
|
" a[x] = 0;\n"
|
||||||
|
"}";
|
||||||
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));
|
||||||
|
|
Loading…
Reference in New Issue