memleak: uncommented and fixed the handling of switch

This commit is contained in:
Daniel Marjamäki 2008-08-31 07:42:54 +00:00
parent b88fd769a7
commit aba1ef0d0e
2 changed files with 22 additions and 16 deletions

View File

@ -146,14 +146,14 @@ static void MemoryLeak( const TOKEN *tok, const char varname[] )
ReportErr( errmsg.str() ); ReportErr( errmsg.str() );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
/*
static void instoken(TOKEN *tok, const char str[]) static void instoken(TOKEN *tok, const char str[])
{ {
TOKEN *newtok = new TOKEN; TOKEN *newtok = new TOKEN;
memcpy( newtok, tok, sizeof(TOKEN) ); memcpy( newtok, tok, sizeof(TOKEN) );
newtok->str = strdup(str); newtok->str = strdup(str);
tok->next = newtok; tok->next = newtok;
}*/ }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -453,29 +453,35 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
erase(tok2, gettok(tok2,3)); erase(tok2, gettok(tok2,3));
done = false; done = false;
} }
/*
// Replace switch with if (if not complicated) // Replace switch with if (if not complicated)
if (Match(tok2, "switch {")) if (Match(tok2, "switch {"))
{ {
// Right now, I just handle if there are a few case and perhaps a default. // Right now, I just handle if there are a few case and perhaps a default.
bool valid = true; bool valid = false;
bool incase = false; bool incase = false;
for ( const TOKEN * _tok = gettok(tok2,2); valid && _tok; _tok = _tok->next ) for ( const TOKEN * _tok = gettok(tok2,2); valid && _tok; _tok = _tok->next )
{ {
if ( _tok->str[0] == '{' ) if ( _tok->str[0] == '{' )
valid = false;
else if ( _tok->str[0] == '}' )
break; break;
else if (strncmp(_tok->str,"if",2)==0) else if ( _tok->str[0] == '}' )
valid = false; {
valid = true;
break;
}
else if (strncmp(_tok->str,"loop",2)==0) else if (strncmp(_tok->str,"if",2)==0)
valid = false; break;
else if (strcmp(_tok->str,"switch")==0)
break;
else if (strcmp(_tok->str,"loop")==0)
break;
else if (incase && Match(_tok,"case")) else if (incase && Match(_tok,"case"))
valid = false; break;
incase |= Match(_tok,"case"); incase |= Match(_tok,"case");
incase &= !Match(_tok,"break"); incase &= !Match(_tok,"break");
@ -515,7 +521,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
} }
} }
} }
*/
} }
} }

View File

@ -49,8 +49,8 @@ public:
TEST_CASE( forwhile3 ); TEST_CASE( forwhile3 );
TEST_CASE( forwhile4 ); TEST_CASE( forwhile4 );
//TEST_CASE( switch1 ); TEST_CASE( switch1 );
//TEST_CASE( switch2 ); TEST_CASE( switch2 );
TEST_CASE( mismatch1 ); TEST_CASE( mismatch1 );