From 7e8b3c86f63860ac6b5515fb2a29a23f42ad2aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Nov 2008 17:02:06 +0000 Subject: [PATCH] Memory leak: Better handling of 'if (0 != p)' --- CheckMemoryLeak.cpp | 3 ++- testmemleak.cpp | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 1d2dc1b62..4538fce89 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -357,7 +357,8 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list // if else switch if ( Match(tok, "if ( %var1% )", varnames) || - Match(tok, "if ( %var1% != 0 )", varnames) ) + Match(tok, "if ( %var1% != 0 )", varnames) || + Match(tok, "if ( 0 != %var1% )", 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 90ea8e866..bf53b5af8 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -411,18 +411,18 @@ private: "}\n" ); 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() ); - } - + + void if3() + { + check( "void f()\n" + "{\n" + " char *s = new char[100];\n" + " if (0 != s)\n" + " foo(s);\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } +