![]() |
![]() |
2801 | ![]() |
||||
![]() | |||||||
| Overflow and wraparound | |||||||
A definite anomaly has been detected. Examination of the context indicates that overflow will always occur when this expression is evaluated. In the example below, the relational expression in the "if" statement determines that the value of n will always exceed 10000 at the point where it is multiplied by 4. If the size of an int is only 16 bits, overflow will inevitably result because 40000 cannot be represented in signed 16 bit arithmetic.
/*PRQA S 2017,2983,2986,3120,3199,3203,3227,3408 ++*/
/*****************************************/
/* OPTIONS: -s int=16 */
/*****************************************/
void foo(int n)
{
int x;
if (n > 10000)
{
x = n * 4; /* 2801 */
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |