| 445 | //--------------------------------------------------------------------------- |
| 446 | |
| 447 | void CheckTypeImpl::checkFloatToIntegerOverflow() |
| 448 | { |
| 449 | logChecker("CheckType::checkFloatToIntegerOverflow"); |
| 450 | |
| 451 | for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 452 | const ValueType *vtint, *vtfloat; |
| 453 | |
| 454 | // Explicit cast |
| 455 | if (Token::Match(tok, "( %name%") && tok->astOperand1() && !tok->astOperand2()) { |
| 456 | if (isUnreachableOperand(tok)) |
| 457 | continue; |
| 458 | vtint = tok->valueType(); |
| 459 | vtfloat = tok->astOperand1()->valueType(); |
| 460 | checkFloatToIntegerOverflow(tok, vtint, vtfloat, tok->astOperand1()->values()); |
| 461 | } |
| 462 | |
| 463 | // Assignment |
| 464 | else if (tok->str() == "=" && tok->astOperand1() && tok->astOperand2()) { |
| 465 | if (isUnreachableOperand(tok)) |
| 466 | continue; |
| 467 | vtint = tok->astOperand1()->valueType(); |
| 468 | vtfloat = tok->astOperand2()->valueType(); |
| 469 | checkFloatToIntegerOverflow(tok, vtint, vtfloat, tok->astOperand2()->values()); |
| 470 | } |
| 471 | |
| 472 | else if (tok->str() == "return" && tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->isFloat()) { |
| 473 | if (isUnreachableOperand(tok)) |
| 474 | continue; |
| 475 | const Scope *scope = tok->scope(); |
| 476 | while (scope && scope->type != ScopeType::eLambda && scope->type != ScopeType::eFunction) |
| 477 | scope = scope->nestedIn; |
| 478 | if (scope && scope->type == ScopeType::eFunction && scope->function && scope->function->retDef) { |
| 479 | const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, mSettings); |
| 480 | vtfloat = tok->astOperand1()->valueType(); |
| 481 | checkFloatToIntegerOverflow(tok, &valueType, vtfloat, tok->astOperand1()->values()); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | void CheckTypeImpl::checkFloatToIntegerOverflow(const Token *tok, const ValueType *vtint, const ValueType *vtfloat, const std::list<ValueFlow::Value> &floatValues) |
| 488 | { |
no test coverage detected