From 06776c6ac7142e89c1f8c023546164f89c2fd4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 23 Mar 2009 18:34:59 +0100 Subject: [PATCH] Fixed the testcase TestMemleak::realloc3 --- src/checkmemoryleak.cpp | 9 +++++---- test/testmemleak.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 81e1753ef..734d27a72 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -330,10 +330,11 @@ bool CheckMemoryLeakClass::notvar(const Token *tok, const char *varnames[], bool const std::string end(endpar ? " )" : " [;)&|]"); - return bool(Token::Match(tok, std::string("! " + varname + end).c_str()) || - Token::simpleMatch(tok, std::string("! ( " + varname + " )" + end).c_str()) || - Token::Match(tok, std::string("0 == " + varname + end).c_str()) || - Token::simpleMatch(tok, std::string(varname + " == 0" + end).c_str())); + return bool(Token::Match(tok, ("! " + varname + end).c_str()) || + Token::Match(tok, ("! ( " + varname + " )" + end).c_str()) || + Token::Match(tok, ("0 == " + varname + end).c_str()) || + Token::Match(tok, (varname + " == 0" + end).c_str()) || + Token::Match(tok, ("( " + varname + " ) == 0" + end).c_str())); } Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype, bool classmember, bool &all, unsigned int sz) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 7ba08ee0c..c1ef2acbb 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -164,7 +164,7 @@ private: TEST_CASE(realloc1); TEST_CASE(realloc2); - // TODO TEST_CASE(realloc3); + TEST_CASE(realloc3); TEST_CASE(assign); @@ -657,14 +657,14 @@ private: { check("static void f()\n" "{\n" - " char *buf = NULL, *tmp;\n" - " if (!(tmp = realloc(buf, 50)))\n" - " {\n" - " free(buf);\n" - " return NULL;\n" - " }\n" - " buf = tmp;\n" - " return buf;\n" + " char *buf = NULL, *tmp;\n" + " if (!(tmp = realloc(buf, 50)))\n" + " {\n" + " free(buf);\n" + " return NULL;\n" + " }\n" + " buf = tmp;\n" + " return buf;\n" "}\n"); ASSERT_EQUALS(std::string(""), errout.str()); } @@ -673,11 +673,11 @@ private: { check("static void f()\n" "{\n" - " char *buf = malloc(10);\n" - " if (aa)\n" - " ;\n" + " char *buf = malloc(10);\n" + " if (aa)\n" + " ;\n" " else if (buf = realloc(buf, 100))\n" - " ;\n" + " ;\n" " free(buf);\n" "}\n"); ASSERT_EQUALS(std::string(""), errout.str()); @@ -1487,8 +1487,8 @@ private: check("class A\n" "{\n" "public:\n" - " void a();\n" - " void doNothing() { }\n" + " void a();\n" + " void doNothing() { }\n" "};\n" "\n" "void A::a()\n" @@ -1505,9 +1505,9 @@ private: check("class A\n" "{\n" "public:\n" - " int * p;\n" - " A();\n" - " ~A();\n" + " int * p;\n" + " A();\n" + " ~A();\n" "};\n" "\n" "A::A()\n"