[previous] 2911 [next] Definite: Wraparound in unsigned arithmetic operation.
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 */
    }
}


No MISRA C:2012 Rules applicable to message 2911


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