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

View File

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