| 353 | //----------------------------------------------------------------------------- |
| 354 | |
| 355 | void CheckSizeofImpl::sizeofFunction() |
| 356 | { |
| 357 | if (!mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("sizeofFunctionCall")) |
| 358 | return; |
| 359 | |
| 360 | logChecker("CheckSizeof::sizeofFunction"); // warning |
| 361 | |
| 362 | for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 363 | if (Token::simpleMatch(tok, "sizeof (")) { |
| 364 | |
| 365 | // ignore if the `sizeof` result is cast to void inside a macro, i.e. the calculation is |
| 366 | // expected to be parsed but skipped, such as in a disabled custom ASSERT() macro |
| 367 | if (tok->isExpandedMacro() && tok->previous()) { |
| 368 | const Token *cast_end = (tok->strAt(-1) == "(") ? tok->previous() : tok; |
| 369 | if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") || |
| 370 | Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) { |
| 371 | continue; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | if (const Token *argument = tok->next()->astOperand2()) { |
| 376 | const Token *checkToken = argument->previous(); |
| 377 | if (checkToken->tokType() == Token::eName) |
| 378 | continue; |
| 379 | const Function * fun = checkToken->function(); |
| 380 | // Don't report error if the function is overloaded |
| 381 | if (fun && fun->nestedIn->functionMap.count(checkToken->str()) == 1) { |
| 382 | sizeofFunctionError(tok); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | void CheckSizeofImpl::sizeofFunctionError(const Token *tok) |
| 390 | { |
no test coverage detected