Fixed #5721 (valueFlowBeforeCondition: stop when goto label is seen)
This commit is contained in:
parent
ead3f28e06
commit
3300d39854
|
@ -440,6 +440,13 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
||||||
if (tok2->str() == ")" && Token::Match(tok2->link()->previous(), "typeof|sizeof ("))
|
if (tok2->str() == ")" && Token::Match(tok2->link()->previous(), "typeof|sizeof ("))
|
||||||
tok2 = tok2->link();
|
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 (tok2->str() == "}") {
|
||||||
if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) {
|
if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) {
|
||||||
if (settings->debugwarnings) {
|
if (settings->debugwarnings) {
|
||||||
|
@ -487,13 +494,6 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// goto label
|
|
||||||
if (Token::Match(tok2, "[;{}] %var% :")) {
|
|
||||||
if (settings->debugwarnings)
|
|
||||||
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on goto label");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,7 +455,22 @@ private:
|
||||||
"out:"
|
"out:"
|
||||||
" if (x==123){}\n"
|
" 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() {
|
void valueFlowAfterAssign() {
|
||||||
|
|
Loading…
Reference in New Issue