Uninitialized variables: Fixed TODO assertion (related with ticket #3106)
This commit is contained in:
parent
d3ce3e78bd
commit
b6f4dbd067
|
@ -430,10 +430,16 @@ private:
|
|||
// is there assignment or ternary operator in the return statement?
|
||||
bool assignment = false;
|
||||
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
|
||||
if (tok2->str() == "=" || (!isC && tok2->str() == ">>") || tok2->str() == "?" || Token::Match(tok2, "(|, &")) {
|
||||
if (tok2->str() == "=" || (!isC && tok2->str() == ">>") || Token::Match(tok2, "(|, &")) {
|
||||
assignment = true;
|
||||
break;
|
||||
}
|
||||
if (Token::Match(tok2, "[(,] &| %var% [,)]")) {
|
||||
tok2 = tok2->next();
|
||||
if (!tok2->isName())
|
||||
tok2 = tok2->next();
|
||||
ExecutionPath::bailOutVar(checks, tok2->varId());
|
||||
}
|
||||
}
|
||||
|
||||
if (!assignment) {
|
||||
|
|
|
@ -575,6 +575,7 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: y\n", errout.str());
|
||||
|
||||
{
|
||||
// Ticket #3106 - False positive
|
||||
checkUninitVar("int f() {\n"
|
||||
" int i;\n"
|
||||
|
@ -582,12 +583,12 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #3106 - False negative
|
||||
checkUninitVar("int f() {\n"
|
||||
" int i;\n"
|
||||
" return x() ? i : 0;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: i\n", "", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout.str());
|
||||
}
|
||||
|
||||
// Ticket #3480 - Don't crash garbage code
|
||||
checkUninitVar("int f()\n"
|
||||
|
|
Loading…
Reference in New Issue