uninitialized variables: fixed false negatives when uninitialized pointer data is read
This commit is contained in:
parent
6d94c4f15e
commit
239d264432
|
@ -3469,6 +3469,10 @@ private:
|
||||||
{
|
{
|
||||||
use(checks, tok.next());
|
use(checks, tok.next());
|
||||||
}
|
}
|
||||||
|
else if (Token::Match(tok.next(), "%var% ["))
|
||||||
|
{
|
||||||
|
use_array_or_pointer_data(checks, tok.next());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok.varId())
|
if (tok.varId())
|
||||||
|
@ -3617,9 +3621,12 @@ private:
|
||||||
|
|
||||||
bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks)
|
bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks)
|
||||||
{
|
{
|
||||||
if (tok.varId() && Token::Match(&tok, "%var% <|<=|==|!=|)|["))
|
if (tok.varId() && Token::Match(&tok, "%var% <|<=|==|!=|)"))
|
||||||
use(checks, &tok);
|
use(checks, &tok);
|
||||||
|
|
||||||
|
else if (Token::Match(&tok, "!| %var% ["))
|
||||||
|
use_array_or_pointer_data(checks, tok.str() == "!" ? tok.next() : &tok);
|
||||||
|
|
||||||
else if (Token::Match(&tok, "!| %var% ("))
|
else if (Token::Match(&tok, "!| %var% ("))
|
||||||
{
|
{
|
||||||
std::list<const Token *> var;
|
std::list<const Token *> var;
|
||||||
|
|
|
@ -1992,6 +1992,20 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *p = malloc(64);\n"
|
||||||
|
" if (p[0]) { }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *p = malloc(64);\n"
|
||||||
|
" return p[0];\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: p\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("void f()\n"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" Fred *fred = new Fred;\n"
|
" Fred *fred = new Fred;\n"
|
||||||
|
|
Loading…
Reference in New Issue