Skip to content

A4-7-1: Exclude pointer increment/decrement expressions #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions change_notes/2024-01-17-a4-7-1-exclude-pointers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `A4-7-1` - exclude pointer increment and decrement operators from this rule.
6 changes: 6 additions & 0 deletions cpp/autosar/test/rules/A4-7-1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions cpp/common/src/codingstandards/cpp/Overflow.qll
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down