if statements : bug fix and refactorings in the checking for "if (condition);"

This commit is contained in:
Daniel Marjamäki 2008-12-31 07:42:50 +00:00
parent 6167c22eb9
commit da1b84b199
1 changed files with 16 additions and 17 deletions

View File

@ -200,24 +200,24 @@ void CheckOther::redundantCondition2()
void CheckOther::WarningIf()
{
// Search for 'if (condition);'
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->str() == "if")
{
if (!TOKEN::simpleMatch(tok, "if ("))
continue;
// Search for the end paranthesis for the condition..
int parlevel = 0;
for (const TOKEN *tok2 = tok->next(); tok2; tok2 = tok2->next())
{
if (tok2->str() == "(")
parlevel++;
++parlevel++;
else if (tok2->str() == ")")
{
parlevel--;
--parlevel;
if ( parlevel <= 0 )
{
if (strcmp(tok2->strAt(1), ";") == 0 &&
strcmp(tok2->strAt(2), "else") != 0)
if ( TOKEN::Match(tok2, ") ; !!else") )
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Found \"if (condition);\"";
@ -228,7 +228,6 @@ void CheckOther::WarningIf()
}
}
}
}
// Search for 'a=b; if (a==b)'
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())