Fixed #5721 (valueFlowBeforeCondition: stop when goto label is seen)

This commit is contained in:
Daniel Marjamäki 2014-04-28 06:21:48 +02:00
parent ead3f28e06
commit 3300d39854
2 changed files with 23 additions and 8 deletions

View File

@ -440,6 +440,13 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
if (tok2->str() == ")" && Token::Match(tok2->link()->previous(), "typeof|sizeof ("))
tok2 = tok2->link();
// goto label
if (Token::Match(tok2, "[;{}] %var% :")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2->next(), "variable " + var->nameToken()->str() + " stopping on goto label");
break;
}
if (tok2->str() == "}") {
if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) {
if (settings->debugwarnings) {
@ -487,13 +494,6 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
break;
}
}
// goto label
if (Token::Match(tok2, "[;{}] %var% :")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on goto label");
break;
}
}
}
}

View File

@ -455,7 +455,22 @@ private:
"out:"
" if (x==123){}\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on goto label\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (debug) ValueFlow bailout: variable x stopping on goto label\n", errout.str());
// #5721 - FP
bailout("static void f(int rc) {\n"
" ABC* abc = getabc();\n"
" if (!abc) { goto out };\n"
"\n"
" abc->majortype = 0;\n"
" if (FAILED(rc)) {}\n"
"\n"
"out:\n"
" if (abc) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: assignment of abc\n"
"[test.cpp:8]: (debug) ValueFlow bailout: variable abc stopping on goto label\n",
errout.str());
}
void valueFlowAfterAssign() {