From 5a9530340503d9e4ac316ee5c69e3af1ce04efb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Sep 2010 21:15:19 +0200 Subject: [PATCH] Memory leaks: reduce 'loop { if continue ;' to 'loop {' --- lib/checkmemoryleak.cpp | 9 ++++++++- test/testmemleak.cpp | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 592083eed..66b9fe8d0 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1860,13 +1860,20 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Reduce "loop if break ; => ";" + // Reduce "loop if break|continue ; !!else" => ";" if (Token::Match(tok2->next(), "loop if break|continue ; !!else")) { Token::eraseTokens(tok2, tok2->tokAt(4)); done = false; } + // Reduce "loop { if break|continue ; !!else" => "loop {" + if (Token::Match(tok2, "loop { if break|continue ; !!else")) + { + Token::eraseTokens(tok2->next(), tok2->tokAt(5)); + done = false; + } + // Replace "do ; loop ;" with ";" if (Token::simpleMatch(tok2, "; loop ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index a8246de25..bb7164c5c 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -710,6 +710,7 @@ private: ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;")); ASSERT_EQUALS("; loop use ;", simplifycode("; loop { loop loop use ; } ;")); ASSERT_EQUALS("; }", simplifycode("; loop { if break ; break ; } ; }")); + ASSERT_EQUALS("; }", simplifycode("; loop { if continue ; if continue ; } ; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;"));