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

Function truncateImplicitConversion

lib/vf_settokenvalue.cpp:67–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 }
66
67 static Value truncateImplicitConversion(Token* parent, const Value& value, const Settings& settings)
68 {
69 if (!value.isIntValue() && !value.isFloatValue())
70 return value;
71 if (!parent)
72 return value;
73 if (!parent->isBinaryOp())
74 return value;
75 if (!parent->isConstOp() && !parent->isAssignmentOp())
76 return value;
77 if (!astIsIntegral(parent->astOperand1(), false))
78 return value;
79 if (!astIsIntegral(parent->astOperand2(), false))
80 return value;
81 const ValueType* vt1 = parent->astOperand1()->valueType();
82 const ValueType* vt2 = parent->astOperand2()->valueType();
83 // If the sign is the same there is no truncation
84 if (vt1->sign == vt2->sign)
85 return value;
86 const size_t n1 = vt1->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer);
87 const size_t n2 = vt2->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer);
88 ValueType::Sign sign = ValueType::Sign::UNSIGNED;
89 if (n1 < n2)
90 sign = vt2->sign;
91 else // (n1 >= n2)
92 sign = vt1->sign;
93 Value v = castValue(value, sign, std::max(n1, n2) * 8);
94 v.wideintvalue = value.intvalue;
95 return v;
96 }
97
98 static const Token *getCastTypeStartToken(const Token *parent, const Library& library)
99 {

Callers 1

setTokenValueFunction · 0.85

Calls 8

astIsIntegralFunction · 0.85
castValueFunction · 0.85
isBinaryOpMethod · 0.80
isConstOpMethod · 0.80
isAssignmentOpMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
getSizeOfMethod · 0.80

Tested by

no test coverage detected