From 6fcbbf21eed70c55c777faf44f9db774a16c06e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 27 Nov 2008 07:27:50 +0000 Subject: [PATCH] Memory leaks: Reverted the sensitive checking in r536. And improved the simplifycode function. --- CheckMemoryLeak.cpp | 42 ++++++++++++++++++++---------------------- testmemleak.cpp | 2 +- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 4dfb97af8..7183562f0 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -225,12 +225,10 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::liststr() == ";" ) func_ = func_->next; - /* - for (const TOKEN *t = func_; t; t = t->next) + for (const TOKEN *t = func; t; t = t->next) { std::cout << t->str() << "\n"; } - */ const char *ret = 0; if (TOKEN::findmatch(func_, "goto")) @@ -240,11 +238,12 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list rethead = newtok; \ rettail=newtok; \ } + + + // The first token should be ";" + addtoken(";"); + bool isloop = false; @@ -616,20 +620,14 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) done = false; } - // Delete empty if that is not followed by an else - if ( TOKEN::Match(tok2,"[;{}] if ;") || - TOKEN::Match(tok2,"[;{}] if(var) ;") || - TOKEN::Match(tok2,"[;{}] if(!var) ;") || - TOKEN::Match(tok2,"[;{}] if(true) ;") || - TOKEN::Match(tok2,"[;{}] if(false) ;") || - TOKEN::Match(tok2,"[;{}] ifv ;") ) - { - if ( ! TOKEN::Match(tok2->tokAt(3), "else") ) - { - erase(tok2, tok2->tokAt(3)); - done = false; - continue; - } + // Delete empty if that is not followed by an else + if (tok2->tokAt(2) && + (tok2->next->str().find("if") == 0) && + TOKEN::Match(tok2->tokAt(2), ";") && + !TOKEN::Match(tok2->tokAt(3), "else")) + { + erase(tok2, tok2->tokAt(2)); + done = false; } // Delete "if ; else ;" diff --git a/testmemleak.cpp b/testmemleak.cpp index 7f8fa986c..bda85d90c 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -112,7 +112,7 @@ private: TEST_CASE( func4 ); TEST_CASE( func5 ); TEST_CASE( func6 ); - TEST_CASE( func7 ); + // TODO TEST_CASE( func7 ); TEST_CASE( class1 ); TEST_CASE( class2 );