Fix ctunullpointer FP (#4471)
This commit is contained in:
parent
888721ea12
commit
45ccc9ba1e
|
@ -146,6 +146,12 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) const
|
||||||
return isPointerDeRef(tok, unknown, mSettings);
|
return isPointerDeRef(tok, unknown, mSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isUnevaluated(const Token* tok) {
|
||||||
|
if (tok && Token::Match(tok->previous(), "sizeof|decltype ("))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Settings *settings)
|
bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Settings *settings)
|
||||||
{
|
{
|
||||||
unknown = false;
|
unknown = false;
|
||||||
|
@ -182,7 +188,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Dereferencing pointer..
|
// Dereferencing pointer..
|
||||||
if (parent->isUnaryOp("*")) {
|
if (parent->isUnaryOp("*") && !isUnevaluated(parent->astParent())) {
|
||||||
// declaration of function pointer
|
// declaration of function pointer
|
||||||
if (tok->variable() && tok->variable()->nameToken() == tok)
|
if (tok->variable() && tok->variable()->nameToken() == tok)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4341,6 +4341,15 @@ private:
|
||||||
" g(x);\n"
|
" g(x);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
ctu("size_t f(int* p) {\n"
|
||||||
|
" size_t len = sizeof(*p);\n"
|
||||||
|
" return len;\n"
|
||||||
|
"}\n"
|
||||||
|
"void g() {\n"
|
||||||
|
" f(NULL);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue