Uninitialized variables: detect usage of dead pointer: '*p += 10'
This commit is contained in:
parent
95bfa50d7e
commit
a90a7202cb
|
@ -486,9 +486,28 @@ private:
|
|||
if (Token::Match(tok.tokAt(-2), "[;{}] *"))
|
||||
{
|
||||
if (Token::simpleMatch(tok.next(), "="))
|
||||
init_pointer(checks, &tok);
|
||||
else
|
||||
{
|
||||
// is the pointer used in the rhs?
|
||||
bool used = false;
|
||||
for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (Token::Match(tok2, "[,;=(]"))
|
||||
break;
|
||||
else if (Token::Match(tok2, "* %varid%", tok.varId()))
|
||||
{
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (used)
|
||||
use_pointer(checks, &tok);
|
||||
else
|
||||
init_pointer(checks, &tok);
|
||||
}
|
||||
else
|
||||
{
|
||||
use_pointer(checks, &tok);
|
||||
}
|
||||
return &tok;
|
||||
}
|
||||
|
||||
|
|
|
@ -376,8 +376,7 @@ private:
|
|||
" char *s = malloc(100);\n"
|
||||
" *s += 10;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
|
||||
|
||||
checkUninitVar("void f()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue