Checkers:PRECISION.LOSS

From current

Reference > C/C++ checkers > PRECISION.LOSS

This issue is reported when an implicit cast to a smaller data type may cause a loss of precision (data).

Mitigation and prevention

If the loss of precision cast is intentional, the source of the cast should be masked with an appropriate bitmask. For example:

char c = (i & 0xFF);

Example 1

1  void foo(int i) {
2      char c;
3      c = i; // PRECISION.LOSS
4  }

Security Guidelines