Fixed #875 (Uninitialized variable: initialization in subfunction)
This commit is contained in:
parent
6ac2b6ab14
commit
45df223bfb
|
@ -1211,6 +1211,21 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va
|
|||
// goto ")"
|
||||
tok = tok ? tok->link() : 0;
|
||||
|
||||
// Check if the condition contains the variable
|
||||
if (tok)
|
||||
{
|
||||
for (const Token *tok2 = tok->link(); tok2 && tok2 != tok; tok2 = tok2->next())
|
||||
{
|
||||
// The variable may be initialized..
|
||||
// if (someFunction(&var)) ..
|
||||
if (tok2->varId())
|
||||
{
|
||||
init = true;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// goto "{"
|
||||
tok = tok ? tok->next() : 0;
|
||||
|
||||
|
|
|
@ -988,6 +988,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f()\n"
|
||||
"{\n"
|
||||
" C *c;\n"
|
||||
" if (fun(&c));\n"
|
||||
" c->Release();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// switch..
|
||||
checkUninitVar("char * f()\n"
|
||||
"{\n"
|
||||
|
@ -1022,7 +1030,6 @@ private:
|
|||
" return i;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue