Revert "Fixed false negative #5815"

This reverts commit dc6c278d83.
This commit is contained in:
PKEuS 2015-09-09 14:46:47 +02:00
parent 47f64df8aa
commit fbbdfa85ca
4 changed files with 3 additions and 27 deletions

View File

@ -251,7 +251,7 @@ void CheckSizeof::sizeofCalculation()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "sizeof (")) { if (Token::simpleMatch(tok, "sizeof (")) {
const Token *argument = tok->next()->astOperand2(); 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()); sizeofCalculationError(argument, argument->isExpandedMacro());
} }
} }

View File

@ -1136,19 +1136,8 @@ void Token::astOperand2(Token *tok)
_astOperand2 = 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%|++|--")) if (!Token::Match(this, "%cop%|++|--"))
return false; return false;

View File

@ -872,10 +872,9 @@ public:
* For '*' and '&' tokens it is looked up if this is a * For '*' and '&' tokens it is looked up if this is a
* dereference or address-of. A dereference or address-of is not * dereference or address-of. A dereference or address-of is not
* counted as a calculation. * 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 * @return returns true if current token is a calculation
*/ */
bool isCalculation(bool goDownwards = false) const; bool isCalculation() const;
void clearAst() { void clearAst() {
_astOperand1 = _astOperand2 = _astParent = NULL; _astOperand1 = _astOperand2 = _astParent = NULL;

View File

@ -108,18 +108,6 @@ private:
check("sizeof(--foo)"); check("sizeof(--foo)");
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); 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() { void sizeofForArrayParameter() {