C and C++ Binaries


LANG.ARITH.BIGSHIFT : Shift Amount Exceeds Bit Width

Summary

data << shift_amount
/* or */
data >> shift_amount

occurs with shift_amount greater than the size (in bits) of data's type.

Properties

Class Name Shift Amount Exceeds Bit Width
Significance security
Mnemonic LANG.ARITH.BIGSHIFT
Categories
MisraC2023 MisraC2023:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  MisraC2023:12.2 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
Misra2012 Misra2012:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  Misra2012:12.2 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
Misra2004 Misra2004:12.8 The right-hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left-hand operand
AUTOSARC++14 AUTOSARC++14:M5-8-1 The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand.
MisraC++2008 MisraC++2008:5-8-1 The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left hand operand.
MisraC++2023 MisraC++2023:4.1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  MisraC++2023:7.0.4 The operands of bitwise operators and shift operators shall be appropriate
CWE CWE:758 Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
  CWE:1335 Incorrect Bitwise Shift of Integer
CERT-C CERT-C:INT34-C Do not shift an expression by a negative number of bits or by greater than or equal to the number of bits that exist in the operand
  CERT-C:INT35-C Use correct integer precisions
JSF++ JSF++:164 The right hand operand of a shift operator shall lie between zero and one less than the width in bits of the left-hand operand (inclusive).
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Shift Amount Exceeds Bit Width"

Example

int do_bigshift(void){
    int a = 50;
    int b = a << 200;   /* 'Shift Amount Exceeds Bit Width' warning issued here */
    return a+b;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.