Fixed #3793 (improve check: calculation in sizeof)
This commit is contained in:
parent
04661fd7d0
commit
c3a65dca40
|
@ -3007,7 +3007,8 @@ void CheckOther::sizeofCalculation()
|
|||
if (Token::simpleMatch(tok, "sizeof (")) {
|
||||
const Token* const end = tok->linkAt(1);
|
||||
for (const Token *tok2 = tok->tokAt(2); tok2 != end; tok2 = tok2->next()) {
|
||||
if (tok2->isOp() && (!tok2->isExpandedMacro() || _settings->inconclusive) && !Token::Match(tok2, ">|<|&|*")) {
|
||||
if (tok2->isOp() && (!tok2->isExpandedMacro() || _settings->inconclusive) && !Token::Match(tok2, ">|<|&") && (Token::Match(tok2->previous(), "%var%") || !Token::Match(tok2, "*"))) {
|
||||
if (!(Token::Match(tok2->previous(), "%type%") || Token::Match(tok2->next(), "%type%"))) {
|
||||
sizeofCalculationError(tok2, tok2->isExpandedMacro());
|
||||
break;
|
||||
}
|
||||
|
@ -3015,6 +3016,7 @@ void CheckOther::sizeofCalculation()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOther::sizeofCalculationError(const Token *tok, bool inconclusive)
|
||||
{
|
||||
|
|
|
@ -1366,12 +1366,18 @@ private:
|
|||
}
|
||||
|
||||
void sizeofCalculation() {
|
||||
check("sizeof(a+b)");
|
||||
check("int a, b; int a,sizeof(a+b)");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str());
|
||||
|
||||
check("sizeof(-a)");
|
||||
check("int a, b; sizeof(a*b)");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str());
|
||||
|
||||
check("int a, b; sizeof(-a)");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof()\n", errout.str());
|
||||
|
||||
check("int a, b; sizeof(*a)");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("sizeof(void * const)");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue