Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Integer type ranges are defined by the JLS, §4.2.1, "Integral Types and Values" [JLS 2005], and are also described in rule NUM00-J. Detect or prevent integer overflow.

The following table presents the rules for narrowing primitive conversions of integer types. In the table, for an integer type T, n represents the number of bits used to represent the resulting type T (precision).

...

Note that conversions from float to double or from double to float can also lose information about the overall magnitude of the converted value. See rule NUM06-J. Use the strictfp modifier for floating-point calculation consistency across platforms for additional information.

Noncompliant Code Example (Integer Narrowing)

...

The CERT C Secure Coding Standard

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

The CERT C++ Secure Coding Standard

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="e8368921428ea57c-6384d16a-4b0c4a5b-99e4836a-94bb628b640fefdba6a44a20"><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>

MITRE CWE

CWE-681. Incorrect conversion between numeric types

 

CWE-197. Numeric truncation error

...