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 ")"
|
// goto ")"
|
||||||
tok = tok ? tok->link() : 0;
|
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 "{"
|
// goto "{"
|
||||||
tok = tok ? tok->next() : 0;
|
tok = tok ? tok->next() : 0;
|
||||||
|
|
||||||
|
@ -1333,7 +1348,7 @@ void CheckOther::uninitvar()
|
||||||
{
|
{
|
||||||
if (Token::Match(tok->next(), "return|goto"))
|
if (Token::Match(tok->next(), "return|goto"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// if it's a pointer, dereferencing is forbidden
|
// if it's a pointer, dereferencing is forbidden
|
||||||
const bool pointer(tok->strAt(2) == std::string("*"));
|
const bool pointer(tok->strAt(2) == std::string("*"));
|
||||||
|
|
||||||
|
|
|
@ -988,6 +988,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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..
|
// switch..
|
||||||
checkUninitVar("char * f()\n"
|
checkUninitVar("char * f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1022,7 +1030,6 @@ private:
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue