diff --git a/change_notes/2024-01-17-a4-7-1-exclude-pointers.md b/change_notes/2024-01-17-a4-7-1-exclude-pointers.md new file mode 100644 index 0000000000..325149b219 --- /dev/null +++ b/change_notes/2024-01-17-a4-7-1-exclude-pointers.md @@ -0,0 +1 @@ + * `A4-7-1` - exclude pointer increment and decrement operators from this rule. \ No newline at end of file diff --git a/cpp/autosar/test/rules/A4-7-1/test.cpp b/cpp/autosar/test/rules/A4-7-1/test.cpp index 7f6cbb7abe..60c3a1a391 100644 --- a/cpp/autosar/test/rules/A4-7-1/test.cpp +++ b/cpp/autosar/test/rules/A4-7-1/test.cpp @@ -62,4 +62,10 @@ void test_loop_bound_bad(unsigned int n) { i++) { // NON_COMPLIANT - crement will overflow before loop bound is // reached } +} + +void test_pointer() { + int *p = nullptr; + p++; // COMPLIANT - not covered by this rule + p--; // COMPLIANT - not covered by this rule } \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/Overflow.qll b/cpp/common/src/codingstandards/cpp/Overflow.qll index 130e1bb42d..3de3a43bf6 100644 --- a/cpp/common/src/codingstandards/cpp/Overflow.qll +++ b/cpp/common/src/codingstandards/cpp/Overflow.qll @@ -1,5 +1,5 @@ /** - * This module provides predicates for checking whether an operation overflows or wraps. + * This module provides predicates for checking whether an integer operation overflows, underflows or wraps. */ import cpp @@ -10,10 +10,12 @@ import codingstandards.cpp.dataflow.TaintTracking import semmle.code.cpp.valuenumbering.GlobalValueNumbering /** - * An operation that may overflow or underflow. + * An integer operation that may overflow, underflow or wrap. */ class InterestingOverflowingOperation extends Operation { InterestingOverflowingOperation() { + // We are only interested in integer experssions + this.getUnderlyingType() instanceof IntegralType and // Might overflow or underflow ( exprMightOverflowNegatively(this)