Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

PRECISION.LOSS.CALL

Loss of precision during function call

The PRECISION.LOSS checker finds instances in which an implicit cast to a smaller data type during a function call can cause a loss of precision in data.

Vulnerability and risk

Depending on the exact circumstances, this situation is potentially exploitable, for instance if it results in a buffer overflow.

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);

Vulnerable code example

1  void foo(unsigned char v);
2  void test(unsigned long data){
3    foo(data);   
4  }

Klocwork flags line 3, in which an unsigned long is converted to an unsigned char.

Related checkers