Fixed #1282 (False positive for a memory leak in a simple loop)
This commit is contained in:
parent
f49cc7f0ff
commit
85fcd4c9a9
|
@ -1448,6 +1448,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce "alloc loop !var alloc ;" => "alloc ;"
|
||||||
|
if (Token::Match(tok2, "[;{}] alloc ; loop !var alloc ;"))
|
||||||
|
{
|
||||||
|
Token::eraseTokens(tok2, tok2->tokAt(5));
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Reduce "if(var) dealloc ;" and "if(var) use ;" that is not followed by an else..
|
// Reduce "if(var) dealloc ;" and "if(var) use ;" that is not followed by an else..
|
||||||
if (Token::Match(tok2, "[;{}] if(var) assign|dealloc|use ; !!else"))
|
if (Token::Match(tok2, "[;{}] if(var) assign|dealloc|use ; !!else"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -555,6 +555,12 @@ private:
|
||||||
Token::eraseTokens(tok, tok->tokAt(5));
|
Token::eraseTokens(tok, tok->tokAt(5));
|
||||||
tok->str("if(!var)");
|
tok->str("if(!var)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (Token::simpleMatch(tok, "! var"))
|
||||||
|
{
|
||||||
|
tok->deleteNext();
|
||||||
|
tok->str("!var");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -635,6 +641,8 @@ private:
|
||||||
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
||||||
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
|
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
|
||||||
|
|
||||||
|
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; loop !var alloc ;"));
|
||||||
|
|
||||||
ASSERT_EQUALS("; alloc ; dealloc ; return ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } }"));
|
ASSERT_EQUALS("; alloc ; dealloc ; return ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } }"));
|
||||||
ASSERT_EQUALS("; alloc ; dealloc ; return ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { continue ; } }"));
|
ASSERT_EQUALS("; alloc ; dealloc ; return ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { continue ; } }"));
|
||||||
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { break ; } }"));
|
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { break ; } }"));
|
||||||
|
|
Loading…
Reference in New Issue