Fixed #2938 (Uninitialized variable not detected when part of expression)

This commit is contained in:
Daniel Marjamäki 2011-07-24 22:26:11 +02:00
parent 7346d07871
commit 1bb7a1c23c
2 changed files with 19 additions and 0 deletions

View File

@ -471,6 +471,18 @@ private:
} }
} }
if (tok.str() == "return")
{
for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next())
{
if (tok2->isName() && tok2->strAt(1) == "(")
tok2 = tok2->next()->link();
else if (tok2->varId())
use(checks, tok2);
}
}
if (tok.varId()) if (tok.varId())
{ {
// array variable passed as function parameter.. // array variable passed as function parameter..

View File

@ -168,6 +168,13 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ret\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ret\n", errout.str());
checkUninitVar("static int foo()\n"
"{\n"
" int ret;\n"
" return ret+5;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: ret\n", errout.str());
checkUninitVar("void f()\n" checkUninitVar("void f()\n"
"{\n" "{\n"
" int a;\n" " int a;\n"