diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 059595c54..2f6ee86a2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1521,7 +1521,7 @@ private: dereference(foundError, checks, &tok); else if (Token::Match(tok.tokAt(-2), "return * %var%")) dereference(foundError, checks, &tok); - else if (Token::Match(tok.next(), ". %var%")) + else if (!Token::simpleMatch(tok.tokAt(-2), "& (") && Token::Match(tok.next(), ". %var%")) dereference(foundError, checks, &tok); else if (Token::Match(tok.previous(), "[;{}=+-/(,] %var% [ %any% ]")) dereference(foundError, checks, &tok); diff --git a/test/testother.cpp b/test/testother.cpp index 7ee950c3e..99930949f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -441,7 +441,7 @@ private: strPlusChar("void foo()\n" "{\n" " int i = 1;\n" - " const char* psz = \"Bla\";\n" + " const char* psz = \"Bla\";\n" " const std::string str = i + psz;\n" "}\n"); ASSERT_EQUALS("", errout.str()); @@ -1015,6 +1015,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkNullPointer("void get_offset(long &offset)\n" + "{\n" + " mystruct * temp; temp = 0;\n" + " offset = (long)(&(temp->z));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // function pointer.. checkNullPointer("void foo()\n" "{\n"