Skip to content

Commit 6d17642

Browse files
authored
Merge pull request #476 from geoffw0/av_165
CPP: Fix AV Rule 165
2 parents 2ce2c0a + 3f428a8 commit 6d17642

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
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."
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| test.c:6:6:6:8 | - ... | The unary minus operator should not be applied to an unsigned expression. |
2+
| test.c:9:7:9:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
3+
| test.c:12:7:12:9 | - ... | 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. |
5+
| test.c:19:7:19:23 | - ... | The unary minus operator should not be applied to an unsigned expression. |
6+
| test.c:22:8:22:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
7+
| test.c:23:8:23:11 | - ... | The unary minus operator should not be applied to an unsigned expression. |
8+
| test.c:24:6:24:7 | - ... | The unary minus operator should not be applied to an unsigned expression. |
9+
| test.c:25:7:25:9 | - ... | The unary minus operator should not be applied to an unsigned expression. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jsf/4.21 Operators/AV Rule 165.ql
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
typedef unsigned int TUI;
3+
4+
void f(int i, unsigned int ui, signed int si, TUI tui, volatile unsigned int vui, unsigned u, unsigned short us) {
5+
i = -i;
6+
i = -ui; // BAD
7+
i = -si;
8+
ui = -i;
9+
ui = -ui; // BAD
10+
ui = -si;
11+
si = -i;
12+
si = -ui; // BAD
13+
si = -si;
14+
15+
i = -(int)i;
16+
i = -(unsigned int)i; // BAD
17+
i = -(signed int)i;
18+
ui = -(int)ui;
19+
ui = -(unsigned int)ui; // BAD
20+
ui = -(signed int)ui;
21+
22+
tui = -tui; // BAD
23+
vui = -vui; // BAD
24+
u = -u; // BAD
25+
us = -us; // BAD
26+
ui = -(5U); // BAD [NOT DETECTED]
27+
}

0 commit comments

Comments
 (0)