PRECISION.LOSSLoss of precisionThe PRECISION.LOSS checker finds instances in which an implicit cast to a smaller data type can cause a loss of precision in data. Vulnerability and riskDepending on the exact circumstances, this situation is potentially exploitable, for instance if it results in a buffer overflow. Mitigation and preventionIf 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); Vulnerable code example1 void foo(int i) { 2 char c; 3 c = i; 4 } Klocwork flags line 3, in which there's an implicit cast to a smaller data type, char 'c'. Related checkers |