diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 0862433c2..bb7cb581c 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1431,16 +1431,24 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } - // Replace "loop ;" with ";" - if (Token::simpleMatch(tok2->next(), "loop ;")) + // Replace "do ; loop ;" with ";" + if (Token::Match(tok2->next(), "%any% ; loop ;")) { - Token::eraseTokens(tok2, tok2->tokAt(2)); + if (tok2->next()->str() == "do") + tok2->deleteNext(); + else + tok2 = tok2->next(); + Token::eraseTokens(tok2, tok2->tokAt(3)); done = false; } - // Replace "loop !var ;" with ";" - if (Token::Match(tok2->next(), "loop !var ;")) + // Replace "do ; loop !var ;" with ";" + if (Token::Match(tok2->next(), "%any% ; loop !var ;")) { + if (tok2->next()->str() == "do") + tok2->deleteNext(); + else + tok2 = tok2->next(); Token::eraseTokens(tok2, tok2->tokAt(4)); done = false; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 74035b44e..db9d8a5d6 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -469,6 +469,7 @@ private: ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }")); ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }")); ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;")); + ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;")); // callfunc.. ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;", false));