Fixed #414 (memory leak in if-else construct not detected)
This commit is contained in:
parent
270d2b2d4f
commit
1dd2ec4757
|
@ -1270,6 +1270,30 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Reduce "} else .." => "} if .."
|
||||
if (Token::simpleMatch(tok2, "} else"))
|
||||
{
|
||||
int indentlevel = 0;
|
||||
for (const Token *tok3 = tok2; tok3; tok3 = tok3->previous())
|
||||
{
|
||||
if (tok3->str() == "{")
|
||||
{
|
||||
--indentlevel;
|
||||
if (indentlevel == 0)
|
||||
{
|
||||
if (tok3->previous()->str() == "if")
|
||||
tok2->next()->str("if");
|
||||
}
|
||||
if (indentlevel <= 0)
|
||||
break;
|
||||
}
|
||||
else if (tok3->str() == "}")
|
||||
{
|
||||
++indentlevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove "catch ;"
|
||||
if (Token::simpleMatch(tok2->next(), "catch ;"))
|
||||
{
|
||||
|
|
|
@ -444,11 +444,15 @@ private:
|
|||
ASSERT_EQUALS("; ifv xxx ;", simplifycode("; ifv ; else xxx ;"));
|
||||
|
||||
{
|
||||
const char code[] = "; alloc ; if { dealloc ; return ; }";
|
||||
ASSERT_EQUALS(code, simplifycode(code));
|
||||
ASSERT_EQUALS("; alloc ;", simplifycode(code, true));
|
||||
const char code1[] = "; alloc ; if { dealloc ; return ; }";
|
||||
ASSERT_EQUALS(code1, simplifycode(code1));
|
||||
ASSERT_EQUALS("; alloc ;", simplifycode(code1, true));
|
||||
|
||||
const char code2[] = "; alloc ; if { dealloc ; return ; } else { return ; }";
|
||||
ASSERT_EQUALS("; alloc ; if return ;", simplifycode(code2));
|
||||
}
|
||||
|
||||
|
||||
// switch..
|
||||
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue