Fixed #1628 (false negative: memory leak when using redundant braces)
This commit is contained in:
parent
f0018100e1
commit
d3b5c30c6c
|
@ -1283,6 +1283,34 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
|||
tok2->deleteNext();
|
||||
}
|
||||
|
||||
// remove redundant braces..
|
||||
for (Token *start = tok; start; start = start->next())
|
||||
{
|
||||
if (Token::simpleMatch(start, "; {"))
|
||||
{
|
||||
// the "link" doesn't work here. Find the end brace..
|
||||
unsigned int indent = 0;
|
||||
for (Token *end = start; end; end = end->next())
|
||||
{
|
||||
if (end->str() == "{")
|
||||
++indent;
|
||||
else if (end->str() == "}")
|
||||
{
|
||||
if (indent <= 1)
|
||||
{
|
||||
if (indent == 1 && Token::Match(end->previous(), "[;{}] } %any%"))
|
||||
{
|
||||
start->deleteNext();
|
||||
end->deleteThis();
|
||||
}
|
||||
break;
|
||||
}
|
||||
--indent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reduce the code..
|
||||
bool done = false;
|
||||
while (! done)
|
||||
|
|
|
@ -694,6 +694,12 @@ private:
|
|||
|
||||
ASSERT_EQUALS(";", simplifycode("; do { dealloc ; alloc ; } while(var) ;"));
|
||||
|
||||
// scope..
|
||||
// current result - ok
|
||||
ASSERT_EQUALS("; assign ; dealloc ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
|
||||
// wanted result - better
|
||||
TODO_ASSERT_EQUALS("; assign ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
|
||||
|
||||
// callfunc..
|
||||
ASSERT_EQUALS("; callfunc ;\n;", simplifycode(";callfunc;"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue