Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: literal 0x100000000 is interpreted as int. we need suffix "L" for long (-:

...

Code Block
bgColor#ccccff
long value = /* initialize */;
int i = (int) (value % 0x1000000000x100000000L); // 2^32

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, and for that reason, no performance penalty is incurred.

...

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="0c9b3e0133cd131d-be6fd236-4b4c477c-942b8679-29dbf86fbd062959b2b857e8"><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

...