Skip to content

Commit 9efce94

Browse files
committed
M5-0-20: Exclude pointer assign from bitwise assign
This query was erroneously reporting pointer assign as a bitwise assign operator.
1 parent 47c8a57 commit 9efce94

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `M5-0-20` - exclude pointer assignment operators as bitwise operators.

cpp/autosar/src/rules/M5-0-20/BitwiseOperatorOperandsHaveDifferentUnderlyingType.ql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ predicate isBinaryBitwiseOperation(Operation o, VariableAccess l, VariableAccess
2222
l = bbo.getLeftOperand() and r = bbo.getRightOperand()
2323
)
2424
or
25-
exists(AssignBitwiseOperation abo | abo = o | l = abo.getLValue() and r = abo.getRValue())
25+
exists(AssignBitwiseOperation abo |
26+
abo = o and
27+
// exclude += and -= on pointers, which seem to be erroneously included
28+
// in the database schema
29+
not abo instanceof AssignPointerAddExpr and
30+
not abo instanceof AssignPointerSubExpr
31+
|
32+
l = abo.getLValue() and
33+
r = abo.getRValue()
34+
)
2635
}
2736

2837
from Operation o, Variable left, Variable right

cpp/autosar/test/rules/M5-0-20/test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@ void test463_2_instantiations() {
7171
char shift2 = 2;
7272
test463_2(val, shift2);
7373
}
74+
75+
void test_add(char *val) {
76+
int add = 2;
77+
val += add; // COMPLIANT
78+
}

0 commit comments

Comments
 (0)