![]() |
![]() |
2833 | ![]() |
||||
![]() | |||||||
| Overflow and wraparound | |||||||
Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable. An integer division or remainder operation is being performed. Examination of the immediate context suggests that the divisor could sometimes be zero. For example, in the code shown below, the variable 'x', will be zero unless the parameter 'n' is greater than 0.
/*PRQA S 585,2017,2983,2986,3103,3120,3199,3203,3227,3408 ++*/
void foo(int n)
{
int r;
int i;
int x = 0;
for (i = 0; i < n; ++i)
{
x = x + i;
}
r = 10 / x; /* 2833 */
}
No MISRA C:2012 Rules applicable to message 2833
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |