Memory leaks: remove redundant 'if return ; else|'

This commit is contained in:
Daniel Marjamäki 2010-09-12 21:41:13 +02:00
parent aae2986361
commit 84d9282da2
2 changed files with 13 additions and 3 deletions

View File

@ -1549,6 +1549,16 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
} }
} }
if (Token::Match(tok, ";| if return ;"))
{
tok->deleteThis();
tok->deleteThis();
if (tok->str() == "return")
tok->deleteThis();
if (tok->strAt(1) == "else")
tok->deleteNext();
}
// simplify "while1" contents.. // simplify "while1" contents..
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) for (Token *tok2 = tok; tok2; tok2 = tok2->next())
{ {

View File

@ -695,9 +695,9 @@ private:
// switch.. // switch..
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;")); ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;"));
ASSERT_EQUALS("; if return ;", simplifycode("; switch { case ; return ; default ; break ; }")); ASSERT_EQUALS(";", simplifycode("; switch { case ; return ; default ; break ; }"));
ASSERT_EQUALS("; if return ;", simplifycode("; switch { case ; if { return ; } break ; default ; break ; }")); ASSERT_EQUALS(";", simplifycode("; switch { case ; if { return ; } break ; default ; break ; }"));
ASSERT_EQUALS("; if return ; else use ;", simplifycode("; switch { case ; return ; default ; use ; break ; }")); ASSERT_EQUALS("; use ;", simplifycode("; switch { case ; return ; default ; use ; break ; }"));
ASSERT_EQUALS("; use ;", simplifycode("; while1 { loop { ; } switch { case ; dealloc ; return ; default ; break ; } }")); ASSERT_EQUALS("; use ;", simplifycode("; while1 { loop { ; } switch { case ; dealloc ; return ; default ; break ; } }"));
ASSERT_EQUALS("; { dealloc ; return ; } }", simplifycode("switch { case ; case ; dealloc ; return ; default ; dealloc ; return ; } }")); ASSERT_EQUALS("; { dealloc ; return ; } }", simplifycode("switch { case ; case ; dealloc ; return ; default ; dealloc ; return ; } }"));