[previous] 2791 [next] Definite: Right hand operand of shift operator is negative or too large.
Shift operations

A definite anomaly has been detected. Examination of the context indicates that the value of the right hand operand (i.e. the number of bits to be shifted) is always out of range. According to the ISO-C standard, if the value is either negative or greater than or equal to the width in bits of the left hand operand (after integral promotion), behavior is undefined.

In the code below, the size of a long is assumed to be 32 bits. If the value of si is less than 0 or greater than 31 the resulting behavior is undefined.


/*PRQA S 1253,1277,1279,1575,1594,2017,2983,2986,3120,3198,3199,3203,3227,3408,4131 ++*/
void f1(unsigned long ul, int si)
{
    if (si > 40)
    {
        ul = ul << si;                /* 2791 */
    }
}

void f2(unsigned long ul, int si)
{
    if (si < 0)
    {
        ul = ul << si;                /* 2791 */
    }
}

See also:

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