From a79e979ae48e9216529ebc780022102fd192477a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 20 Apr 2011 17:16:09 +0200 Subject: [PATCH] Memory leaks: Fixed TODO test case. Ticket: #2733 --- lib/checkmemoryleak.cpp | 16 ++++++++-------- test/testmemleak.cpp | 4 +--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 4886f6986..7b3c18ab9 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1812,6 +1812,14 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } + // outer/inner if blocks. Remove outer condition.. + else if (Token::Match(tok2->next(), "if|if(var) { if return use ; }")) + { + tok2->tokAt(6)->deleteNext(); + Token::eraseTokens(tok2, tok2->tokAt(3)); + done = false; + } + else if (tok2->next() && tok2->next()->str() == "if") { // Delete empty if that is not followed by an else @@ -1902,14 +1910,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Remove outer condition.. - else if (Token::Match(tok2->next(), "if { if return use ; }")) - { - tok2->tokAt(6)->deleteNext(); - Token::eraseTokens(tok2, tok2->tokAt(3)); - done = false; - } - continue; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 84ad6be75..36f47b27a 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -669,9 +669,7 @@ private: // remove outer if (#2733) ASSERT_EQUALS("alloc ; return ; }", simplifycode("alloc ; if { if return use ; } return ; }")); ASSERT_EQUALS("alloc ; return ; }", simplifycode("alloc ; if { if(var) return use ; } return ; }")); - TODO_ASSERT_EQUALS("alloc ; return ; }", - "alloc ; if(var) { if return use ; } return ; }", - simplifycode("alloc ; if(var) { if return use ; } return ; }")); + ASSERT_EQUALS("alloc ; return ; }", simplifycode("alloc ; if(var) { if return use ; } return ; }")); // "if ; .." ASSERT_EQUALS("; if xxx ;", simplifycode("; if ; else xxx ;"));