...
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 right shifts are implemented using the following instructions on x86-32:
Code Block |
---|
sarl %cl, %eax |
The sarl
instructions take a bit mask of the least significant 5 bits from %cl
to produce a value in the range [0, 31] and then shift %eax
that many bits:
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
CodeSonar |
| LANG.ARITH.BIGSHIFT | Shift amount exceeds bit width | ||||||
|
| 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 | |||||||
| 51 S, 403 S, 479 S | Partially implemented | |||||||
Parasoft C/C++test | 9.5 | MISRA-038 | |||||||
PRQA QA-C |
| 0499 | Partially implemented | ||||||
Cppcheck |
| shiftNegative, shiftTooManyBits | Context sensitive analysis |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...