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

The right hand operand of this shift operation is a constant expression with a value which is not permitted. The value must be less than the number of bits in the type of the left hand operand and must not be negative.

For example, if the type of the left hand operand is unsigned long, and long is implemented in 32 bits, the value of the right hand operand must not be less than 0 or greater than 31.

Notice that objects of small integer type will undergo integral promotion before being shifted. It may therefore be possible to shift objects of such types by an amount greater than their original width but the value resulting from such an operation may depend on the implemented size of type int.


/*PRQA S 2017,3120,3408,3447 ++*/

extern unsigned long ula;

extern void foo(void)
{
    ula = ula << -2;                  /* 2790      */
    ula = ula << 40;                  /* 2790 2921 */
}


MISRA C:2012 Rules applicable to message 2790:

Rule-12.2  (Required) The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand


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