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::Match(tok.tokAt(-2), "[;{}] *"))
|
||||||
{
|
{
|
||||||
if (Token::simpleMatch(tok.next(), "="))
|
if (Token::simpleMatch(tok.next(), "="))
|
||||||
init_pointer(checks, &tok);
|
{
|
||||||
|
// 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
|
else
|
||||||
|
{
|
||||||
use_pointer(checks, &tok);
|
use_pointer(checks, &tok);
|
||||||
|
}
|
||||||
return &tok;
|
return &tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -376,8 +376,7 @@ private:
|
||||||
" char *s = malloc(100);\n"
|
" char *s = malloc(100);\n"
|
||||||
" *s += 10;\n"
|
" *s += 10;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
|
|
||||||
checkUninitVar("void f()\n"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue