From da1b84b1994b7eea76477397b2e57745750626b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 31 Dec 2008 07:42:50 +0000 Subject: [PATCH] if statements : bug fix and refactorings in the checking for "if (condition);" --- checkother.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/checkother.cpp b/checkother.cpp index c83e022e3..0a8fadc30 100644 --- a/checkother.cpp +++ b/checkother.cpp @@ -200,31 +200,30 @@ 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()) { - int parlevel = 0; - for (const TOKEN *tok2 = tok->next(); tok2; tok2 = tok2->next()) + if (tok2->str() == "(") + ++parlevel++; + else if (tok2->str() == ")") { - if (tok2->str() == "(") - parlevel++; - else if (tok2->str() == ")") + --parlevel; + if ( parlevel <= 0 ) { - parlevel--; - if (parlevel<=0) + if ( TOKEN::Match(tok2, ") ; !!else") ) { - if (strcmp(tok2->strAt(1), ";") == 0 && - strcmp(tok2->strAt(2), "else") != 0) - { - std::ostringstream ostr; - ostr << _tokenizer->fileLine(tok) << ": Found \"if (condition);\""; - _errorLogger->reportErr(ostr.str()); - } - break; + std::ostringstream ostr; + ostr << _tokenizer->fileLine(tok) << ": Found \"if (condition);\""; + _errorLogger->reportErr(ostr.str()); } + break; } } }