uninitialized variables: fixed false positives for member variables
This commit is contained in:
parent
c424d4c8af
commit
768225bb1b
|
@ -1266,8 +1266,23 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va
|
|||
|
||||
void CheckOther::uninitvar()
|
||||
{
|
||||
// start of function..
|
||||
const Token *tok = _tokenizer->tokens();
|
||||
while (0 != (tok = Token::findmatch(tok, "[{};] %type% *| %var% ;")))
|
||||
while (0 != (tok = Token::findmatch(tok, ") const| {")))
|
||||
{
|
||||
// Scan through this scope and check all variables..
|
||||
unsigned int indentlevel = 0;
|
||||
for (; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok->str() == "}")
|
||||
{
|
||||
if (indentlevel <= 1)
|
||||
break;
|
||||
--indentlevel;
|
||||
}
|
||||
if (Token::Match(tok, "[{};] %type% *| %var% ;"))
|
||||
{
|
||||
// goto the variable
|
||||
tok = tok->tokAt(2);
|
||||
|
@ -1278,11 +1293,14 @@ void CheckOther::uninitvar()
|
|||
if (tok->varId() == 0)
|
||||
continue;
|
||||
|
||||
// check if variable is accessed uninitialized..
|
||||
bool init = false;
|
||||
const Token *tokerr = uninitvar_checkscope(tok->next(), tok->varId(), init);
|
||||
if (tokerr)
|
||||
uninitvarError(tokerr, tok->str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOther::checkZeroDivision()
|
||||
|
|
|
@ -968,7 +968,7 @@ private:
|
|||
" int i;\n"
|
||||
" int a() { return i; }\n"
|
||||
"};\n");
|
||||
TODO_ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue