[previous] 2803 [next] Suspicious: Overflow in signed arithmetic operation.
Overflow and wraparound

Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable.

Examination of the immediate context suggests that the evaluation of this expression could sometimes result in integer overflow.

For example, in the code shown below, arithmetic overflow will occur unless the parameter 'n' is greater than 0.


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

    for (i = 0; i < n; ++i)
    {
        x = 3;
    }

    x = 10000 * x;                   /* 2803 */
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents