diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 0802f1fb7..9f3a33ba8 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1234,8 +1234,11 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr()); + if (tok->strAt(1) == "(") + tok = tok->next()->link(); + } // Assignment.. if (varid) { @@ -1414,7 +1417,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) const // Insert extra ";" for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { if (!tok2->previous() || Token::Match(tok2->previous(), "[;{}]")) { - if (Token::Match(tok2, "assign|callfunc|use assign|callfunc|use")) { + if (Token::Match(tok2, "assign|callfunc|use assign|callfunc|use|}")) { tok2->insertToken(";"); } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e8a8ab0b4..f8c590fec 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -572,6 +572,9 @@ private: getcode("char *s = new char[10];\n" "struct ab { int a, b; };\n" "delete [] s;\n", "s")); + + // #4405 - catch + ASSERT_EQUALS(";;catch{}", getcode("char *s; catch(err) { }", "s")); } @@ -765,6 +768,7 @@ private: ASSERT_EQUALS("; callfunc ; }", simplifycode(";callfunc callfunc ; }")); ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }")); ASSERT_EQUALS("; }", simplifycode("loop callfunc ; }")); + ASSERT_EQUALS("alloc ; dealloc ; }", simplifycode("alloc ; if { dealloc ; callfunc } dealloc ; }")); // #4405 // #2900 - don't report false positive ASSERT_EQUALS("; alloc ; if { if { dealloc ; callfunc ; } return ; } dealloc ; }",