diff --git a/src/checkother.cpp b/src/checkother.cpp index fc5bde097..8ef7c59a7 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -82,7 +82,7 @@ void CheckOther::WarningRedundantCode() varname1 = tok->strAt(2); tok2 = tok->tokAt(4); } - else if (Token::Match(tok, "if ( %var% != NULL )")) + else if (Token::Match(tok, "if ( %var% != 0 )")) { varname1 = tok->strAt(2); tok2 = tok->tokAt(6); diff --git a/test/testother.cpp b/test/testother.cpp index 6b5381d76..89986865b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -145,6 +145,13 @@ private: " delete p;\n" "}\n"); ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); + + check("void foo()\n" + "{\n" + " if (p != NULL)\n" + " delete p;\n" + "}\n"); + ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); } void unreachable1()