| 478 | } |
| 479 | |
| 480 | void CheckNullPointerImpl::arithmetic() |
| 481 | { |
| 482 | logChecker("CheckNullPointer::arithmetic"); |
| 483 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 484 | for (const Scope * scope : symbolDatabase->functionScopes) { |
| 485 | for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { |
| 486 | if (!Token::Match(tok, "-|+|+=|-=|++|--")) |
| 487 | continue; |
| 488 | const Token *pointerOperand; |
| 489 | const Token *numericOperand; |
| 490 | if (tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->pointer != 0) { |
| 491 | pointerOperand = tok->astOperand1(); |
| 492 | numericOperand = tok->astOperand2(); |
| 493 | } else if (tok->astOperand2() && tok->astOperand2()->valueType() && tok->astOperand2()->valueType()->pointer != 0) { |
| 494 | pointerOperand = tok->astOperand2(); |
| 495 | numericOperand = tok->astOperand1(); |
| 496 | } else |
| 497 | continue; |
| 498 | if (numericOperand && numericOperand->valueType() && !numericOperand->valueType()->isIntegral()) |
| 499 | continue; |
| 500 | const ValueFlow::Value* numValue = numericOperand ? numericOperand->getValue(0) : nullptr; |
| 501 | if (numValue && numValue->intvalue == 0) // don't warn for arithmetic with 0 |
| 502 | continue; |
| 503 | const ValueFlow::Value* value = pointerOperand->getValue(0); |
| 504 | if (!value) |
| 505 | continue; |
| 506 | if (!mSettings.certainty.isEnabled(Certainty::inconclusive) && value->isInconclusive()) |
| 507 | continue; |
| 508 | if (value->condition && !mSettings.severity.isEnabled(Severity::warning)) |
| 509 | continue; |
| 510 | if (value->condition) |
| 511 | redundantConditionWarning(tok, value, value->condition, value->isInconclusive()); |
| 512 | else |
| 513 | pointerArithmeticError(tok, value, value->isInconclusive()); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | static std::string arithmeticTypeString(const Token *tok) |
| 519 | { |
no test coverage detected