Skip to content

Commit d1adc0e

Browse files
committed
CPP: Fix for explicitly cast expressions.
1 parent 3028e85 commit d1adc0e

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

cpp/ql/src/jsf/4.21 Operators/AV Rule 164.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ predicate constantValue(Expr e, int value) {
3535
predicate violation(BinaryBitwiseOperation op, int lhsBytes, int value) {
3636
(op instanceof LShiftExpr or op instanceof RShiftExpr) and
3737
constantValue(op.getRightOperand(), value) and
38-
lhsBytes = op.getLeftOperand().getType().getSize() and
38+
lhsBytes = op.getLeftOperand().getExplicitlyConverted().getType().getSize() and
3939
(value < 0 or value >= lhsBytes * 8)
4040
}
4141

cpp/ql/test/query-tests/jsf/4.21 Operators/AV Rule 164/AV Rule 164.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
| test.c:11:2:11:8 | ... << ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |
55
| test.c:18:2:18:9 | ... >> ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 7. |
66
| test.c:21:2:21:8 | ... >> ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |
7-
| test.c:23:2:23:25 | ... >> ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 31. |
7+
| test.c:23:2:23:25 | ... >> ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 7. |
8+
| test.c:26:2:26:24 | ... >> ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |

cpp/ql/test/query-tests/jsf/4.21 Operators/AV Rule 164/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ void f(unsigned char uc, signed char sc, int i) {
2323
((unsigned char)i) >> -1; // BAD
2424
((unsigned char)i) >> 0;
2525
((unsigned char)i) >> 7;
26-
((unsigned char)i) >> 8; // BAD [NOT DETECTED]
26+
((unsigned char)i) >> 8; // BAD
2727
}
2828

0 commit comments

Comments
 (0)