Versions Compared

Key

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

...

The UWIDTH() macro provides the correct width for an unsigned integer type , and is defined in INT19-C. Correctly compute integer widths...; see that rule for more information.

...

Code Block
bgColor#ccccff
langc
#include <limits.h>
 
unsigned int ui_a;
unsigned int ui_b;
unsigned int uresult;

void func(void) {
  /* Initialize ui_a and ui_b */
  if (ui_b >= UWIDTH( unsigned int, UINT_MAX)) {
    /* Handle error condition */
  } else {
    uresult = ui_a >> ui_b;
  }
  /* ... */
}

 The UWIDTH() macro provides the correct width for an unsigned integer type , and is defined in INT19-C. Correctly compute integer widths...; see that rule for more information.

...

GCC has no options to handle shifts by negative amounts or by amounts outside the width of the type predictably or to trap on them; they are always treated as undefined. Processors may reduce the shift amount modulo the width of the type. For example, 32-bit shifts are implemented using the following instructions on IA-32:

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

INT34-C

lowLow

unlikelyUnlikely

mediumMedium

P2

L3

Automated Detection

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

...