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()
|
void CheckOther::uninitvar()
|
||||||
{
|
{
|
||||||
|
// start of function..
|
||||||
const Token *tok = _tokenizer->tokens();
|
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
|
// goto the variable
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
|
@ -1278,12 +1293,15 @@ void CheckOther::uninitvar()
|
||||||
if (tok->varId() == 0)
|
if (tok->varId() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// check if variable is accessed uninitialized..
|
||||||
bool init = false;
|
bool init = false;
|
||||||
const Token *tokerr = uninitvar_checkscope(tok->next(), tok->varId(), init);
|
const Token *tokerr = uninitvar_checkscope(tok->next(), tok->varId(), init);
|
||||||
if (tokerr)
|
if (tokerr)
|
||||||
uninitvarError(tokerr, tok->str());
|
uninitvarError(tokerr, tok->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CheckOther::checkZeroDivision()
|
void CheckOther::checkZeroDivision()
|
||||||
{
|
{
|
||||||
|
|
|
@ -968,7 +968,7 @@ private:
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" int a() { return i; }\n"
|
" int a() { return i; }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
TODO_ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue