ValueFlow: Fixed bad values after break/continue

This commit is contained in:
Daniel Marjamäki 2014-02-17 20:07:38 +01:00
parent c050a92bae
commit 690c37633b
2 changed files with 22 additions and 3 deletions

View File

@ -543,6 +543,12 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
tok2 = tok2->linkAt(2);
}
else if (Token::Match(tok2, "break|continue")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + ". noreturn conditional scope.");
break;
}
if (tok2->varId() == varid) {
// bailout: assignment
if (Token::Match(tok2->previous(), "!!* %var% =")) {

View File

@ -571,7 +571,7 @@ private:
code = "void f(int a) {\n"
" int x = a;\n"
" b = x;\n"
" b = x;\n" // <- line 3
" if (a!=132) {}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 132));
@ -581,9 +581,22 @@ private:
" if (n) { a = n; }\n"
" else { a = 0; }\n"
" int x = a;\n"
" if (a > 0) { a = b / x; }\n"
" if (a > 0) { a = b / x; }\n" // <- line 6
"}";
ASSERT_EQUALS(false, testValueOfX(code, 6U, 0));
ASSERT_EQUALS(false, testValueOfX(code, 6U, 0)); // x is not 0 at line 6
// break
code = "void f() {\n"
" for (;;) {\n"
" int x = 1;\n"
" if (!abc()) {\n"
" x = 2;\n"
" break;\n"
" }\n"
" a = x;\n" // <- line 8
" }\n"
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 8U, 2)); // x is not 2 at line 8
}
void valueFlowForLoop() {