MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkFloatToIntegerOverflow

Method checkFloatToIntegerOverflow

lib/checktype.cpp:447–485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445//---------------------------------------------------------------------------
446
447void 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
487void CheckTypeImpl::checkFloatToIntegerOverflow(const Token *tok, const ValueType *vtint, const ValueType *vtfloat, const std::list<ValueFlow::Value> &floatValues)
488{

Callers 1

runChecksMethod · 0.45

Calls 9

isUnreachableOperandFunction · 0.85
nextMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
scopeMethod · 0.80
isIntegralMethod · 0.80
strMethod · 0.45
isFloatMethod · 0.45
isEnabledMethod · 0.45

Tested by

no test coverage detected