Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In almost every case, an attempt to shift by a negative number of bits or by more bits than exist in the operand indicates a bug (logic error). This A logic error is different from overflow, where in which there is simply a representational deficiency. (See INT32-C. Ensure that operations on signed integers do not result in overflow.)

...

The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. According to the C Standard, if E1 has an unsigned type, the value of the result is E1 * 2E2, reduced modulo one 1 more than the maximum value representable in the result type.

...

Making assumptions about whether a right shift is implemented as an arithmetic (signed) shift or a logical (unsigned) shift can also lead to vulnerabilities. See INT13-C. Use bitwise operators only on unsigned operands.

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Can detect violations of this rule. Unsigned operands are detected when checking for INT13-C. Use bitwise operators only on unsigned operands

ECLAIR
Include Page
ECLAIR_V
ECLAIR_V
CC2.INT34Partially implemented

Fortify SCA

5.0

 

Can detect violations of this rule with CERT C Rule Pack

LDRA tool suite

Include Page
LDRA_V
LDRA_V

403 S

Partially implemented

PRQA QA-C
Include Page
PRQA_V
PRQA_V

0499
0500
0501
2790
2791 (D)
2792 (A)
2793 (S)

Partially implemented

...

[Dowd 2006]Chapter 6, "C Language Issues"
[ISO/IEC C99 Rationale 2003]Section Subclause 6.5.7, "Bitwise Shift Operators"
[Seacord 2013]Chapter 5, "Integer Security"
[Viega 2005]Section 5.2.7, "Integer Overflow"

...