Skip to content

Commit 3f428a8

Browse files
committed
CPP: Fix for explicitly cast expressions.
1 parent 5cddabb commit 3f428a8

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import cpp
1111
// see MISRA Rule 5-3-2
1212

1313
from UnaryMinusExpr ume
14-
where ume.getOperand().getUnderlyingType().(IntegralType).isUnsigned()
14+
where ume.getOperand().getExplicitlyConverted().getUnderlyingType().(IntegralType).isUnsigned()
1515
and not ume.getOperand() instanceof Literal
1616
select ume, "The unary minus operator should not be applied to an unsigned expression."

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
| test.c:6:6:6:8 | - ... | The unary minus operator should not be applied to an unsigned expression. |
22
| test.c:9:7:9:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
33
| test.c:12:7:12:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
4-
| test.c:18:7:18:14 | - ... | The unary minus operator should not be applied to an unsigned expression. |
4+
| test.c:16:6:16:21 | - ... | The unary minus operator should not be applied to an unsigned expression. |
55
| test.c:19:7:19:23 | - ... | The unary minus operator should not be applied to an unsigned expression. |
6-
| test.c:20:7:20:21 | - ... | The unary minus operator should not be applied to an unsigned expression. |
76
| test.c:22:8:22:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
87
| test.c:23:8:23:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
98
| test.c:24:6:24:7 | - ... | The unary minus operator should not be applied to an unsigned expression. |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ void f(int i, unsigned int ui, signed int si, TUI tui, volatile unsigned int vui
1313
si = -si;
1414

1515
i = -(int)i;
16-
i = -(unsigned int)i; // BAD [NOT DETECTED]
16+
i = -(unsigned int)i; // BAD
1717
i = -(signed int)i;
18-
ui = -(int)ui; // [FALSE POSITIVE]
18+
ui = -(int)ui;
1919
ui = -(unsigned int)ui; // BAD
20-
ui = -(signed int)ui; // [FALSE POSITIVE]
20+
ui = -(signed int)ui;
2121

2222
tui = -tui; // BAD
2323
vui = -vui; // BAD

0 commit comments

Comments
 (0)