From f1330c3db0f9e1eed632669cc0fcbee43ebc33f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 2 Nov 2008 10:33:38 +0000 Subject: [PATCH] memleak: fixed false positives for assignment in return statement (bug 2205568) --- testmemleak.cpp | 16 ++++++++++++++++ tokenize.cpp | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/testmemleak.cpp b/testmemleak.cpp index 405e5c554..86039e528 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -76,6 +76,8 @@ private: TEST_CASE( switch1 ); TEST_CASE( switch2 ); + TEST_CASE( ret ); + TEST_CASE( mismatch1 ); TEST_CASE( func1 ); @@ -410,6 +412,20 @@ private: + void ret() + { + check( "char *f( char **str )\n" + "{\n" + " char *ret = malloc( 10 );\n" + " return *str = ret;\n" + "}\n" ); + + ASSERT_EQUALS( std::string(""), errout.str() ); + } + + + + void mismatch1() diff --git a/tokenize.cpp b/tokenize.cpp index 123676636..80dd94b5a 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -888,9 +888,9 @@ void SimplifyTokenList() continue; TOKEN *type0 = tok->next; - if (!type0) - break; - if (strcmp(type0->str, "else") == 0) + if (!Match(type0, "%type%")) + continue; + if (Match(type0, "else") || Match(type0, "return")) continue; TOKEN *tok2 = NULL;