![]() |
![]() |
2832 | ![]() |
||||
![]() | |||||||
| Overflow and wraparound | |||||||
An apparent anomaly has been detected. Preceding operations imply that this expression will sometimes result in division by zero. For example, in the code shown below, the expression in the "if" statement implies that the value of n is expected to be 0 - sometimes, and so should never be used as a divisor. Of course, if the value of n is never actually zero, the division operation will always be valid; but this would imply that the "if" statement is redundant and any code contained in the "if" block is also redundant.
/*PRQA S 585,2017,2983,2986,3103,3199,3203,3227,3408 ++*/
void foo(int x, int n)
{
int r;
if (n == 0)
{
}
r = x / n; /* 2832 */
}
MISRA-C:2004 Rules applicable to message 2832:
| 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 |