[previous] 2801 [next] Definite: Overflow in signed arithmetic operation.
Overflow and wraparound

A definite anomaly has been detected. Examination of the context indicates that overflow will always occur when this expression is evaluated.

In the example below, the relational expression in the "if" statement determines that the value of n will always exceed 10000 at the point where it is multiplied by 4. If the size of an int is only 16 bits, overflow will inevitably result because 40000 cannot be represented in signed 16 bit arithmetic.


/*PRQA S 2017,2983,2986,3120,3199,3203,3227,3408 ++*/
/*****************************************/
/* OPTIONS: -s int=16                    */
/*****************************************/
void foo(int n)
{
    int x;

    if (n > 10000)
    {
        x = n * 4;                /* 2801 */
    }
}


MISRA C:2012 Rules applicable to message 2801:

Dir-4.1  (Required) Run-time failures shall be minimized


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