![]() |
![]() |
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 */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |