From b72565bdf6cb45c08d4d958d2fe618a9e5741a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 11 Dec 2008 07:10:57 +0000 Subject: [PATCH] memory leak : Minor fixes to make the unit tests work --- CheckMemoryLeak.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 5518dd655..498884729 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -643,6 +643,14 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) done = false; } + // Reduce "if* ;" that is not followed by an else.. + if (TOKEN::Match(tok2->next(), "if(var)|if(!var)|if(true)|if(false)|ifv ;") && + !TOKEN::Match(tok2->tokAt(3), "else")) + { + erase(tok2, tok2->tokAt(2)); + done = false; + } + // Reduce "if if" => "if" if ( TOKEN::Match(tok2, "if if") ) { @@ -707,21 +715,20 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) } // Reduce "if ; else return use ;" => "if return use ;" - if ( TOKEN::Match(tok2, "if ; else %var% ;") ) + if ( TOKEN::Match(tok2, "if ; else return use ;") ) { erase( tok2, tok2->tokAt(3) ); done = false; } // Reduce "do { alloc ; } " => "alloc ;" - /* TODO : This could hide memory leaks + // TODO: If the loop can be executed twice reduce to "loop alloc ;" instead if ( TOKEN::Match(tok2->next(), "do { alloc ; }") ) { erase(tok2, tok2->tokAt(3)); erase(tok2->next()->next(), tok2->tokAt(4)); done = false; } - */ // Reduce "loop if break ; => ";" if ( TOKEN::Match( tok2->next(), "loop if break|continue ; ") &&