CheckMemoryLeak: Improved the reducing of "if.."
This commit is contained in:
parent
e2d1be9b0c
commit
d59dd1bf7c
|
@ -378,7 +378,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Delete empty if
|
||||
// Delete empty if that is not followed by an else
|
||||
if ( Match(tok2,"[;{}] if ;") ||
|
||||
Match(tok2,"[;{}] if(var) ;") ||
|
||||
Match(tok2,"[;{}] if(!var) ;") )
|
||||
|
@ -391,18 +391,6 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
}
|
||||
}
|
||||
|
||||
// Delete "else ;" and "else if ;"
|
||||
if ( Match(tok2->next, "else if ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,4));
|
||||
done = false;
|
||||
}
|
||||
if ( Match(tok2->next, "else ;") )
|
||||
{
|
||||
erase(tok2, gettok(tok2,3));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete if block: "alloc; if return use ;"
|
||||
if (Match(tok2,"alloc ; if return use ;") && !Match(gettok(tok2,6),"else"))
|
||||
{
|
||||
|
@ -410,15 +398,6 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Replace "if { dealloc ; return ; }" with "if ;"
|
||||
if (Match(tok2,"if { dealloc ; return ; }"))
|
||||
{
|
||||
erase(tok2, gettok(tok2, 6));
|
||||
free(tok2->next->str);
|
||||
tok2->next->str = strdup(";");
|
||||
done = false;
|
||||
}
|
||||
|
||||
// "[;{}] if alloc ; else return ;" => "[;{}] alloc ;"
|
||||
if (Match(tok2,"[;{}] if alloc ; else return ;"))
|
||||
{
|
||||
|
@ -434,6 +413,18 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Reducing if..
|
||||
if (Match(tok2,"if dealloc ; else") || Match(tok2,"if use ; else"))
|
||||
{
|
||||
erase(tok2, gettok(tok2, 2));
|
||||
done = false;
|
||||
}
|
||||
if (Match(tok2,"[;{}] if { dealloc ; return ; }") && !Match(gettok(tok2,8),"else"))
|
||||
{
|
||||
erase(tok2,gettok(tok2,8));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete "loop ;"
|
||||
if ( Match(tok2->next, "loop ;") )
|
||||
{
|
||||
|
|
|
@ -334,7 +334,7 @@ public:
|
|||
" break;\n"
|
||||
" };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS( std::string("[test.cpp:12]: Memory leak"), errout.str() );
|
||||
ASSERT_EQUALS( std::string("[test.cpp:12]: Memory leak: str\n"), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue