From 84d9282da22cfb01e715af2333bd9786788ac61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Sep 2010 21:41:13 +0200 Subject: [PATCH] Memory leaks: remove redundant 'if return ; else|' --- lib/checkmemoryleak.cpp | 10 ++++++++++ test/testmemleak.cpp | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 66b9fe8d0..d2f9bab82 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1549,6 +1549,16 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) } } + if (Token::Match(tok, ";| if return ;")) + { + tok->deleteThis(); + tok->deleteThis(); + if (tok->str() == "return") + tok->deleteThis(); + if (tok->strAt(1) == "else") + tok->deleteNext(); + } + // simplify "while1" contents.. for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index bb7164c5c..83ecb0d17 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -695,9 +695,9 @@ private: // switch.. ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;")); - ASSERT_EQUALS("; if return ;", simplifycode("; switch { case ; return ; default ; break ; }")); - ASSERT_EQUALS("; if return ;", simplifycode("; switch { case ; if { return ; } break ; default ; break ; }")); - ASSERT_EQUALS("; if return ; else use ;", simplifycode("; switch { case ; return ; default ; use ; break ; }")); + ASSERT_EQUALS(";", simplifycode("; switch { case ; return ; default ; break ; }")); + ASSERT_EQUALS(";", simplifycode("; switch { case ; if { return ; } break ; default ; break ; }")); + ASSERT_EQUALS("; use ;", simplifycode("; switch { case ; return ; default ; use ; break ; }")); ASSERT_EQUALS("; use ;", simplifycode("; while1 { loop { ; } switch { case ; dealloc ; return ; default ; break ; } }")); ASSERT_EQUALS("; { dealloc ; return ; } }", simplifycode("switch { case ; case ; dealloc ; return ; default ; dealloc ; return ; } }"));