diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index d8bd3e7a9..4f4a610ff 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -251,7 +251,7 @@ void CheckSizeof::sizeofCalculation() for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "sizeof (")) { const Token *argument = tok->next()->astOperand2(); - if (argument && argument->isCalculation(true) && (!argument->isExpandedMacro() || printInconclusive)) + if (argument && argument->isCalculation() && (!argument->isExpandedMacro() || printInconclusive)) sizeofCalculationError(argument, argument->isExpandedMacro()); } } diff --git a/lib/token.cpp b/lib/token.cpp index b84744b7a..acb7c25cd 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1136,19 +1136,8 @@ void Token::astOperand2(Token *tok) _astOperand2 = tok; } -bool Token::isCalculation(bool goDownwards) const +bool Token::isCalculation() const { - if (goDownwards && Token::Match(this, "[|(|,")) { - bool ret = false; - if (this->astOperand1()) - ret = this->astOperand1()->isCalculation(true); - if (ret) - return true; - if (this->astOperand2()) - ret = this->astOperand2()->isCalculation(true); - return ret; - - } if (!Token::Match(this, "%cop%|++|--")) return false; diff --git a/lib/token.h b/lib/token.h index 7e81aff6a..69867f1ea 100644 --- a/lib/token.h +++ b/lib/token.h @@ -872,10 +872,9 @@ public: * For '*' and '&' tokens it is looked up if this is a * dereference or address-of. A dereference or address-of is not * counted as a calculation. - * @param goDownwards the function will look for calculations in all children of the tree * @return returns true if current token is a calculation */ - bool isCalculation(bool goDownwards = false) const; + bool isCalculation() const; void clearAst() { _astOperand1 = _astOperand2 = _astParent = NULL; diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index cc5908e41..d681eb179 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -108,18 +108,6 @@ private: check("sizeof(--foo)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); - - check("sizeof(bar(1, 2, --foo, 3, 4))"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); - - check("sizeof( int32_t[ i++ ] );"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); - - check("sizeof(a[b + 2])"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); - - check("sizeof((2 + a)[b])"); - ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); } void sizeofForArrayParameter() {