Skip to content

Commit 158fc86

Browse files
committed
A4-7-1: Exclude pointer increment/decrement expressions
This rule only covers integer expressions.
1 parent d9f0911 commit 158fc86

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `A4-7-1` - exclude pointer increment and decrement operators from this rule.

cpp/autosar/test/rules/A4-7-1/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ void test_loop_bound_bad(unsigned int n) {
6262
i++) { // NON_COMPLIANT - crement will overflow before loop bound is
6363
// reached
6464
}
65+
}
66+
67+
void test_pointer() {
68+
int *p = nullptr;
69+
p++; // COMPLIANT - not covered by this rule
70+
p--; // COMPLIANT - not covered by this rule
6571
}

cpp/common/src/codingstandards/cpp/Overflow.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This module provides predicates for checking whether an operation overflows or wraps.
2+
* This module provides predicates for checking whether an integer operation overflows, underflows or wraps.
33
*/
44

55
import cpp
@@ -10,10 +10,12 @@ import codingstandards.cpp.dataflow.TaintTracking
1010
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1111

1212
/**
13-
* An operation that may overflow or underflow.
13+
* An integer operation that may overflow, underflow or wrap.
1414
*/
1515
class InterestingOverflowingOperation extends Operation {
1616
InterestingOverflowingOperation() {
17+
// We are only interested in integer experssions
18+
this.getUnderlyingType() instanceof IntegralType and
1719
// Might overflow or underflow
1820
(
1921
exprMightOverflowNegatively(this)

0 commit comments

Comments
 (0)