diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 36923922a..181e00ad9 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -380,7 +380,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, const char varname[]) // if else switch if ( Match(tok, "if ( %var1% )", varnames) || - Match(tok, "if ( %var1% != NULL )", varnames) ) + Match(tok, "if ( %var1% != 0 )", varnames) ) { addtoken("if(var)"); tok = Tokenizer::gettok(tok, 3); // Make sure the "use" will not be added diff --git a/testmemleak.cpp b/testmemleak.cpp index 96298d631..4c7d1e0fc 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -86,6 +86,7 @@ private: TEST_CASE( if1 ); TEST_CASE( if2 ); + TEST_CASE( if3 ); TEST_CASE( forwhile1 ); TEST_CASE( forwhile2 ); @@ -412,6 +413,17 @@ private: ASSERT_EQUALS( std::string(""), errout.str() ); } + void if3() + { + check( "void f()\n" + "{\n" + " char *s = new char[100];\n" + " if (s != NULL)\n" + " foo(s);\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } +