| 443 | } |
| 444 | |
| 445 | void CheckOtherImpl::warningIntToPointerCast() |
| 446 | { |
| 447 | if (!mSettings.severity.isEnabled(Severity::portability) && !mSettings.isPremiumEnabled("cstyleCast")) |
| 448 | return; |
| 449 | |
| 450 | logChecker("CheckOther::warningIntToPointerCast"); // portability |
| 451 | |
| 452 | for (const Token* tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 453 | // pointer casting.. |
| 454 | if (!tok->isCast()) |
| 455 | continue; |
| 456 | const Token* from = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1(); |
| 457 | if (!from || !from->isNumber()) |
| 458 | continue; |
| 459 | if (!tok->valueType() || tok->valueType()->pointer == 0) |
| 460 | continue; |
| 461 | if (!MathLib::isIntHex(from->str()) && from->hasKnownIntValue() && from->getKnownIntValue() != 0) { |
| 462 | std::string format; |
| 463 | if (MathLib::isDec(from->str())) |
| 464 | format = "decimal"; |
| 465 | else if (MathLib::isOct(from->str())) |
| 466 | format = "octal"; |
| 467 | else |
| 468 | continue; |
| 469 | intToPointerCastError(tok, format); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void CheckOtherImpl::intToPointerCastError(const Token *tok, const std::string& format) |
| 475 | { |