diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 4fbe58785..b895c6bbd 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -146,6 +146,12 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) const 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) { unknown = false; @@ -182,7 +188,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set return false; // Dereferencing pointer.. - if (parent->isUnaryOp("*")) { + if (parent->isUnaryOp("*") && !isUnevaluated(parent->astParent())) { // declaration of function pointer if (tok->variable() && tok->variable()->nameToken() == tok) return false; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index e0475c95b..e86cebd83 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4341,6 +4341,15 @@ private: " g(x);\n" "}"); 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()); } };