...
The range-checking is unnecessary because the truncation that is normally implicit in a narrowing conversion is made explicit. The compiler will optimize the operation away; hence it incurs , and for that reason, no performance penalty is incurred.
Similar operations may be used for converting to other integral types.
...
INT31-C. Ensure that integer conversions do not result in lost or misinterpreted data | ||||
| FLP34-C. Ensure that floating point conversions are within range of the new type | |||
INT31-CPP. Ensure that integer conversions do not result in lost or misinterpreted data | ||||
| FLP34-CPP. Ensure that floating point conversions are within range of the new type | |||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="06aa40b5e6e71de2-f1a11933-4ae24a95-a18187e0-0679d276072fdfbe5c6bf0a4"><ac:plain-text-body><![CDATA[ | [ISO/IEC TR 24772:2010 | http://www.aitcnet.org/isai/] | "Numeric Conversion Errors [FLC]" | ]]></ac:plain-text-body></ac:structured-macro> |
CWE-681, "Incorrect Conversion between Numeric Types" | ||||
| CWE-197, "Numeric Truncation Error" |
...