Skip to content

M5-2-10: Only report the use of ++/-- with arithmetic operations #489

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 4 commits into from
Feb 22, 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
2 changes: 2 additions & 0 deletions change_notes/2024-01-16-m5-2-10-arith-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`M5-2-10` - `IncrementAndDecrementOperatorsMixedWithOtherOperatorsInExpression.ql`:
- only report use of the increment and decrement operations in conjunction with arithmetic operators, as specified by the rule. Notably we no longer report the expressions of the form `*p++`, which combine increment and dereferencing operations.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Expr

from CrementOperation cop, Operation op, string name
from CrementOperation cop, ArithmeticOperation op, string name
where
not isExcluded(cop) and
not isExcluded(op,
Expand Down
2 changes: 2 additions & 0 deletions cpp/autosar/test/rules/M5-2-10/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ void f1() {
++l1; // COMPLIANT
--l2; // COMPLIANT
l3 = l1 * l2;
int *p;
*p++; // COMPLIANT - * is not an arithmetic operator
}
9 changes: 9 additions & 0 deletions cpp/common/src/codingstandards/cpp/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import cpp
private import semmle.code.cpp.valuenumbering.GlobalValueNumbering
import codingstandards.cpp.AccessPath

/**
* A unary or binary arithmetic operation.
*/
class ArithmeticOperation extends Operation {
ArithmeticOperation() {
this instanceof UnaryArithmeticOperation or this instanceof BinaryArithmeticOperation
}
}

/** A full expression as defined in [intro.execution] of N3797. */
class FullExpr extends Expr {
FullExpr() {
Expand Down