CWE-681: Incorrect Conversion between Numeric Types
Incorrect Conversion between Numeric Types
Weakness ID: 681 (Weakness Base)
Status: Draft
Description
Description Summary
When converting from one data type to another, such as long to
integer, data can be omitted or translated in a way that produces unexpected
values. If the resulting values are used in a sensitive context, then dangerous
behaviors may occur.
Time of Introduction
Implementation
Demonstrative Examples
Example 1
In the following Java example, a float literal is cast to an
integer, thus causing a loss of precision.
(Bad Code)
Java
int i = (int) 33457.8f
Potential Mitigations
Phase
Description
Avoid making conversion between numeric types. Always check for the
allowed ranges.