ATH-shift-neg
In this section:
Synopsis
The left-hand side of a right shift operation might be a negative value.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
The left-hand side of a right shift operation might be a negative value. Because performing a right shift operation on a negative number is implementation-defined, this operation might have unexpected results. This check is identical to CERT-INT34-C_c.
Coding standards
- CERT INT34-C
Do not shift a negative number of bits or more bits than exist in the operand
- CWE 682
Incorrect Calculation
Code examples
The following code example fails the check and will give a warning:
int example(int x) {
return -10 >> x;
}
The following code example passes the check and will not give a warning about this issue:
int example(int x) {
return 10 >> x;
}