CheckMemoryLeaksInFunction: Fixed problems with catch and function calls. Ticket: #4405
This commit is contained in:
parent
8e1e894dff
commit
a84d21f271
|
@ -1234,8 +1234,11 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
}
|
||||
|
||||
// throw..
|
||||
else if (Token::Match(tok, "try|throw|catch"))
|
||||
else if (Token::Match(tok, "try|throw|catch")) {
|
||||
addtoken(&rettail, tok, tok->str());
|
||||
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(";");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ; }",
|
||||
|
|
Loading…
Reference in New Issue