Skip to content

Commit fbbdfa8

Browse files
committed
Revert "Fixed false negative cppcheck-opensource#5815"
This reverts commit dc6c278.
1 parent 47f64df commit fbbdfa8

4 files changed

Lines changed: 3 additions & 27 deletions

File tree

lib/checksizeof.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void CheckSizeof::sizeofCalculation()
251251
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
252252
if (Token::simpleMatch(tok, "sizeof (")) {
253253
const Token *argument = tok->next()->astOperand2();
254-
if (argument && argument->isCalculation(true) && (!argument->isExpandedMacro() || printInconclusive))
254+
if (argument && argument->isCalculation() && (!argument->isExpandedMacro() || printInconclusive))
255255
sizeofCalculationError(argument, argument->isExpandedMacro());
256256
}
257257
}

lib/token.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,19 +1136,8 @@ void Token::astOperand2(Token *tok)
11361136
_astOperand2 = tok;
11371137
}
11381138

1139-
bool Token::isCalculation(bool goDownwards) const
1139+
bool Token::isCalculation() const
11401140
{
1141-
if (goDownwards && Token::Match(this, "[|(|,")) {
1142-
bool ret = false;
1143-
if (this->astOperand1())
1144-
ret = this->astOperand1()->isCalculation(true);
1145-
if (ret)
1146-
return true;
1147-
if (this->astOperand2())
1148-
ret = this->astOperand2()->isCalculation(true);
1149-
return ret;
1150-
1151-
}
11521141
if (!Token::Match(this, "%cop%|++|--"))
11531142
return false;
11541143

lib/token.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,9 @@ class CPPCHECKLIB Token {
872872
* For '*' and '&' tokens it is looked up if this is a
873873
* dereference or address-of. A dereference or address-of is not
874874
* counted as a calculation.
875-
* @param goDownwards the function will look for calculations in all children of the tree
876875
* @return returns true if current token is a calculation
877876
*/
878-
bool isCalculation(bool goDownwards = false) const;
877+
bool isCalculation() const;
879878

880879
void clearAst() {
881880
_astOperand1 = _astOperand2 = _astParent = NULL;

test/testsizeof.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,6 @@ class TestSizeof : public TestFixture {
108108

109109
check("sizeof(--foo)");
110110
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str());
111-
112-
check("sizeof(bar(1, 2, --foo, 3, 4))");
113-
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str());
114-
115-
check("sizeof( int32_t[ i++ ] );");
116-
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str());
117-
118-
check("sizeof(a[b + 2])");
119-
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str());
120-
121-
check("sizeof((2 + a)[b])");
122-
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str());
123111
}
124112

125113
void sizeofForArrayParameter() {

0 commit comments

Comments
 (0)