Memory leak: Further improvements of "simplifycode"
This commit is contained in:
parent
8578df698f
commit
d5506618b6
|
@ -672,17 +672,17 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
|
||||||
if ( TOKEN::Match(tok2->next, "do { alloc ; }") )
|
if ( TOKEN::Match(tok2->next, "do { alloc ; }") )
|
||||||
{
|
{
|
||||||
erase(tok2, tok2->tokAt(3));
|
erase(tok2, tok2->tokAt(3));
|
||||||
erase(tok2->next, tok2->tokAt(3));
|
erase(tok2->next->next, tok2->tokAt(4));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "loop { if break ; } => ";"
|
// Reduce "loop if break ; => ";"
|
||||||
if ( TOKEN::Match( tok2, "loop {" ) &&
|
if ( TOKEN::Match( tok2->next, "loop %var%" ) &&
|
||||||
strncmp(tok2->strAt(2), "if", 2) == 0 &&
|
tok2->tokAt(2)->str().find("if") == 0 &&
|
||||||
(TOKEN::Match( tok2->tokAt(3), "break ; }") || TOKEN::Match( tok2->tokAt(3), "continue ; }")))
|
(TOKEN::Match( tok2->tokAt(3), "break ; ") || TOKEN::Match( tok2->tokAt(3), "continue ;")) &&
|
||||||
|
!TOKEN::Match(tok2->tokAt(5),"else") )
|
||||||
{
|
{
|
||||||
tok2->setstr(";");
|
erase( tok2, tok2->tokAt(4) );
|
||||||
erase( tok2, tok2->tokAt(6) );
|
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,7 +728,8 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
|
||||||
erase(tok2, tok2->tokAt(4));
|
erase(tok2, tok2->tokAt(4));
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
// Delete if block: "alloc; if return use ;"
|
|
||||||
|
// Delete if block: "alloc; if return use ;"
|
||||||
if (TOKEN::Match(tok2,"alloc ; if return use ;") && !TOKEN::Match(tok2->tokAt(6),"else"))
|
if (TOKEN::Match(tok2,"alloc ; if return use ;") && !TOKEN::Match(tok2->tokAt(6),"else"))
|
||||||
{
|
{
|
||||||
erase(tok2, tok2->tokAt(5));
|
erase(tok2, tok2->tokAt(5));
|
||||||
|
@ -741,6 +742,20 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
|
||||||
erase( tok2, tok2->tokAt(4) );
|
erase( tok2, tok2->tokAt(4) );
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce "[;{}] return ; %var%" => "[;{}] return ;"
|
||||||
|
if ( TOKEN::Match(tok2, "[;{}] return ; %var%") )
|
||||||
|
{
|
||||||
|
erase( tok2->next->next, tok2->tokAt(4) );
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce "[;{}] return use ; %var%" => "[;{}] return use ;"
|
||||||
|
if ( TOKEN::Match(tok2, "[;{}] return use ; %var%") )
|
||||||
|
{
|
||||||
|
erase( tok2->next->next->next, tok2->tokAt(5) );
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Reduce "if(var) return use ;" => "return use ;"
|
// Reduce "if(var) return use ;" => "return use ;"
|
||||||
if ( TOKEN::Match(tok2->next, "if(var) return use ;") && !TOKEN::Match(tok2->tokAt(5),"else"))
|
if ( TOKEN::Match(tok2->next, "if(var) return use ;") && !TOKEN::Match(tok2->tokAt(5),"else"))
|
||||||
|
@ -940,6 +955,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
|
||||||
MemoryLeak(last, varname);
|
MemoryLeak(last, varname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// detect cases that "simplifycode" don't handle well..
|
||||||
else if ( _settings._debug )
|
else if ( _settings._debug )
|
||||||
{
|
{
|
||||||
TOKEN *first = tok;
|
TOKEN *first = tok;
|
||||||
|
@ -947,13 +963,15 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
|
||||||
first = first->next;
|
first = first->next;
|
||||||
|
|
||||||
bool noerr = false;
|
bool noerr = false;
|
||||||
noerr |= TOKEN::Match( first, "alloc ; dealloc ;" );
|
noerr |= TOKEN::Match( first, "alloc ; }" );
|
||||||
noerr |= TOKEN::Match( first, "alloc ; return use ;" );
|
noerr |= TOKEN::Match( first, "alloc ; dealloc ; }" );
|
||||||
noerr |= TOKEN::Match( first, "alloc ; use ;" );
|
noerr |= TOKEN::Match( first, "alloc ; return use ; }" );
|
||||||
noerr |= TOKEN::Match( first, "if alloc ; dealloc ;" );
|
noerr |= TOKEN::Match( first, "alloc ; use ; }" );
|
||||||
noerr |= TOKEN::Match( first, "if alloc ; return use ;" );
|
noerr |= TOKEN::Match( first, "if alloc ; dealloc ; }" );
|
||||||
noerr |= TOKEN::Match( first, "if alloc ; use ;" );
|
noerr |= TOKEN::Match( first, "if alloc ; return use ; }" );
|
||||||
noerr |= TOKEN::Match( first, "alloc ; ifv return ; dealloc ;" );
|
noerr |= TOKEN::Match( first, "if alloc ; use ; }" );
|
||||||
|
noerr |= TOKEN::Match( first, "alloc ; ifv return ; dealloc ; }" );
|
||||||
|
noerr |= TOKEN::Match( first, "alloc ; if return ; dealloc; }" );
|
||||||
|
|
||||||
// Unhandled case..
|
// Unhandled case..
|
||||||
if ( ! noerr )
|
if ( ! noerr )
|
||||||
|
@ -965,7 +983,6 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Tokenizer::deleteTokens(tok);
|
Tokenizer::deleteTokens(tok);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue