Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: REM cost reform

...

Casting a numeric value to a narrower type can result in information loss related to the sign and magnitude of the numeric value. As a result, data can be misrepresented or interpreted incorrectly.

Rule

Severity

Likelihood

Detectable

RepairableRemediation Cost

Priority

Level

NUM12-J

Low

Unlikely

Yes

YesMedium

P2P3

L3

Automated Detection

Automated detection of narrowing conversions on integral types is straightforward. Determining whether such conversions correctly reflect the intent of the programmer is infeasible in the general case. Heuristic warnings could be useful.

(Java) (Java) (Java) (Java)
ToolVersionCheckerDescription
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

JAVA.MATH.APPROX.E
JAVA.MATH.APPROX.PI
JAVA.CAST.FTRUNC
JAVA.ARITH.FPEQUAL

Approximate e Constant


Approximate pi Constant


Cast: Integer to Floating Point


Floating Point Equality

Parasoft Jtest
Include Page
Parasoft_V
Parasoft_V
CERT.NUM12.CLPDo not cast primitive data types to lower precision
PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V6124

Related Guidelines

...