![]() |
![]() |
2911 | ![]() |
||||
![]() | |||||||
| Overflow and wraparound | |||||||
An arithmetic operation is being performed in an unsigned type. Examination of the context indicates that the result is always too large to be representable in this type and so wraparound will occur - the result will be truncated using modulo arithmetic. Perhaps this is intended ? For example:
/*PRQA S 1278,2017,2982,2983,2984,2986,3120,3198,3199,3203,3227,3372,3408 ++*/
/*******************************/
/* OPTIONS: -s int=16 */
/*******************************/
void foo(unsigned int un)
{
unsigned unr;
if (un > 40000U)
{
unr = un * 7U; /* 2911 */
unr = un + un; /* 2911 */
}
else
{
unr = un - 50000U; /* 2911 */
}
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |