![]() |
![]() |
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 */
}
}
MISRA-C:2004 Rules applicable to message 2801:
| Rule 21.1 (Required) | Minimisation of run-time failures shall be ensured by the use of at least one of (a) static analysis tools/techniques; (b) dynamic analysis tools/techniques; (c) explicit coding of checks to handle run-time faults |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |