Skip to content

A3-9-1: exclude fps on post increment and decrement operators #625

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
Jul 2, 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-06-18-fix-fp-614-A3-9-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A3-9-1` - `VariableWidthIntegerTypesUsed.ql`:
- Fixes #614. Excludes post increment and decrement operators.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import codingstandards.cpp.autosar
import codingstandards.cpp.EncapsulatingFunctions
import codingstandards.cpp.BuiltInNumericTypes
import codingstandards.cpp.Type
import codingstandards.cpp.Operator

from Variable v, Type typeStrippedOfSpecifiers
where
Expand All @@ -30,5 +31,8 @@ where
typeStrippedOfSpecifiers instanceof UnsignedCharType or
typeStrippedOfSpecifiers instanceof SignedCharType
) and
not v instanceof ExcludedVariable
not v instanceof ExcludedVariable and
//post-increment/post-decrement operators are required by the standard to have a dummy int parameter
not v.(Parameter).getFunction() instanceof PostIncrementOperator and
not v.(Parameter).getFunction() instanceof PostDecrementOperator
select v, "Variable '" + v.getName() + "' has variable-width type."
7 changes: 6 additions & 1 deletion cpp/autosar/test/rules/A3-9-1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ void test_variable_width_type_qualified_variables() {
volatile long l2; // NON_COMPLIANT
volatile unsigned long ul2; // NON_COMPLIANT
volatile signed long sl2; // NON_COMPLIANT
}
}

struct test_fix_fp_614 {
test_fix_fp_614 operator++(int); // COMPLIANT
test_fix_fp_614 operator--(int); // COMPLIANT
};
14 changes: 14 additions & 0 deletions cpp/common/src/codingstandards/cpp/Operator.qll
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ class IncrementOperator extends Operator {
}
}

class PostIncrementOperator extends Operator {
PostIncrementOperator() {
hasName("operator++") and
getNumberOfParameters() = 1
}
}

class PostDecrementOperator extends Operator {
PostDecrementOperator() {
hasName("operator--") and
getNumberOfParameters() = 1
}
}

class StructureDerefOperator extends Operator {
StructureDerefOperator() {
hasName("operator->") and
Expand Down
Loading