...
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 | ||||
---|---|---|---|---|
| ||||
#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 | ||||||
---|---|---|---|---|---|---|---|---|---|
|
| Can detect violations of this rule. Unsigned operands are detected when checking for INT13-C. Use bitwise operators only on unsigned operands | |||||||
ECLAIR |
| CC2.INT34 | Partially implemented | ||||||
5.0 |
| Can detect violations of this rule with CERT C Rule Pack | |||||||
| 403 S | Partially implemented | |||||||
PRQA QA-C |
| 0499 | Partially implemented |
...