Fixed #4778 (FP: Uninitialized variable: av)

This commit is contained in:
Daniel Marjamäki 2013-06-14 07:21:53 +02:00
parent 870d29944b
commit ae36472a1b
2 changed files with 7 additions and 1 deletions

View File

@ -1542,7 +1542,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
if (vartok->previous()->str() == "&") {
const Token *tok2 = vartok->tokAt(-2);
if (tok2 && (tok2->isConstOp() || tok2->str() == "("))
if (tok2 && (tok2->isConstOp() || Token::Match(tok2, "[;{}(]")))
return false; // address of
if (tok2 && tok2->str() == ")")
tok2 = tok2->link()->previous();

View File

@ -2376,6 +2376,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n" // #4778 - cast address of uninitialized variable
" long a;\n"
" &a;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n" // #4717 - ({})
" int a = ({ long b = (long)(123); 2 + b; });\n"
"}", "test.c", false);