Uninitialized variables: Fixed false positive for 'if (ptr)'
This commit is contained in:
parent
a82a085d10
commit
ab7ffd2391
|
@ -1419,6 +1419,8 @@ private:
|
|||
continue;
|
||||
if (mode == 2 && !c->pointer)
|
||||
continue;
|
||||
if (mode == 3 && (c->pointer && c->alloc))
|
||||
continue;
|
||||
|
||||
CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner);
|
||||
if (checkOther)
|
||||
|
@ -1450,6 +1452,11 @@ private:
|
|||
use(foundError, checks, tok, 2);
|
||||
}
|
||||
|
||||
static void use_not_pointer(bool &foundError, std::list<ExecutionPath *> &checks, const Token *tok)
|
||||
{
|
||||
use(foundError, checks, tok, 3);
|
||||
}
|
||||
|
||||
const Token *parse(const Token &tok, bool &foundError, std::list<ExecutionPath *> &checks) const
|
||||
{
|
||||
// Variable declaration..
|
||||
|
@ -1650,7 +1657,7 @@ private:
|
|||
bool foundError = false;
|
||||
|
||||
if (tok.varId() && Token::Match(&tok, "%var% <|<=|==|!=|)|["))
|
||||
use(foundError, checks, &tok);
|
||||
use_not_pointer(foundError, checks, &tok);
|
||||
|
||||
else if (Token::Match(&tok, "!| %var% ("))
|
||||
{
|
||||
|
|
|
@ -1314,6 +1314,20 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void foo()\n"
|
||||
"{\n"
|
||||
" char *a;\n"
|
||||
" if (a);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
|
||||
|
||||
checkUninitVar("void foo()\n"
|
||||
"{\n"
|
||||
" char *a = malloc(100);\n"
|
||||
" if (a);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// struct..
|
||||
checkUninitVar("void f()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue