Fixed #718 (False positive, resource leak when break in a loop before exit)
This commit is contained in:
parent
6a63742dde
commit
482a2f9d95
|
@ -1152,6 +1152,14 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce "if X ; else X ;" => "X ;"
|
||||||
|
else if (Token::Match(tok2->next(), "if %var% ; else %var% ;") &&
|
||||||
|
std::string(tok2->strAt(2)) == std::string(tok2->strAt(5)))
|
||||||
|
{
|
||||||
|
Token::eraseTokens(tok2, tok2->tokAt(5));
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Two "if alloc ;" after one another.. perhaps only one of them can be executed each time
|
// Two "if alloc ;" after one another.. perhaps only one of them can be executed each time
|
||||||
else if (!_settings->_showAll && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
|
else if (!_settings->_showAll && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
|
||||||
{
|
{
|
||||||
|
@ -1373,6 +1381,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce "loop break ; => ";"
|
||||||
|
if (Token::Match(tok2->next(), "loop break|continue ;"))
|
||||||
|
{
|
||||||
|
Token::eraseTokens(tok2, tok2->tokAt(3));
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Reduce "loop if break ; => ";"
|
// Reduce "loop if break ; => ";"
|
||||||
if (Token::Match(tok2->next(), "loop if break|continue ; !!else"))
|
if (Token::Match(tok2->next(), "loop if break|continue ; !!else"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -460,11 +460,10 @@ private:
|
||||||
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc; if(!var) { return; } dealloc;"));
|
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc; if(!var) { return; } dealloc;"));
|
||||||
ASSERT_EQUALS("; alloc ;", simplifycode("; if { alloc; } else { return; }"));
|
ASSERT_EQUALS("; alloc ;", simplifycode("; if { alloc; } else { return; }"));
|
||||||
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc ; if(!var) { alloc ; } dealloc ;"));
|
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc ; if(!var) { alloc ; } dealloc ;"));
|
||||||
|
|
||||||
ASSERT_EQUALS("; use ;", simplifycode("; if(var) use ;"));
|
ASSERT_EQUALS("; use ;", simplifycode("; if(var) use ;"));
|
||||||
|
ASSERT_EQUALS("; break ;", simplifycode("; if break ; else break ;"));
|
||||||
|
|
||||||
ASSERT_EQUALS("; alloc ; dealloc ;\n; alloc ;", simplifycode("; alloc ; if(!var) { return ; } if { dealloc ; }"));
|
ASSERT_EQUALS("; alloc ; dealloc ;\n; alloc ;", simplifycode("; alloc ; if(!var) { return ; } if { dealloc ; }"));
|
||||||
|
|
||||||
ASSERT_EQUALS("; if alloc ; else assign ; return use ;", simplifycode("; callfunc ; if callfunc { alloc ; } else { assign ; } return use ;"));
|
ASSERT_EQUALS("; if alloc ; else assign ; return use ;", simplifycode("; callfunc ; if callfunc { alloc ; } else { assign ; } return use ;"));
|
||||||
|
|
||||||
// "if ; .."
|
// "if ; .."
|
||||||
|
@ -480,6 +479,7 @@ private:
|
||||||
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;"));
|
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;"));
|
||||||
|
|
||||||
// loops..
|
// loops..
|
||||||
|
ASSERT_EQUALS(";", simplifycode("; loop { break; }"));
|
||||||
ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }"));
|
ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }"));
|
||||||
ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }"));
|
ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }"));
|
||||||
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
||||||
|
|
Loading…
Reference in New Issue