diff --git a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected index c0a8359320..3148fb8c7c 100644 --- a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected +++ b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected @@ -1,3 +1,4 @@ | test.c:9:7:9:12 | ... = ... | Use of an assignment operator's result. | | test.c:13:11:13:16 | ... = ... | Use of an assignment operator's result. | | test.c:15:8:15:13 | ... = ... | Use of an assignment operator's result. | +| test.c:17:6:17:13 | ... += ... | Use of an assignment operator's result. | diff --git a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c index db0a45384e..031eee8244 100644 --- a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c +++ b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c @@ -13,4 +13,15 @@ void test() { l1 = l3[l2 = 0]; // NON_COMPLIANT l1 = l2 = 0; // NON_COMPLIANT + + l3[l1 += l2] = l3[l1]; // NON_COMPLIANT + + for (l1 = 0; l1 < 10; l1 += l2) // COMPLIANT + { + } + + while (l1 < 10) // COMPLIANT + { + l1 += l2; // COMPLIANT + } } diff --git a/change_notes/2026-05-18-fix-fp-misra-c-13-4.md b/change_notes/2026-05-18-fix-fp-misra-c-13-4.md new file mode 100644 index 0000000000..bf6b7c1313 --- /dev/null +++ b/change_notes/2026-05-18-fix-fp-misra-c-13-4.md @@ -0,0 +1,4 @@ +- `RULE-13-4` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: + - Fixed false positives and false negatives. +- `RULE-8-18-2` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: + - Fixed false positives and false negatives. diff --git a/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll b/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll index 04a106b5c4..0556248f26 100644 --- a/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll +++ b/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll @@ -11,8 +11,9 @@ abstract class ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery extends Qu Query getQuery() { result instanceof ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery } -query predicate problems(AssignExpr e, string message) { +query predicate problems(Assignment e, string message) { not isExcluded(e, getQuery()) and not exists(ExprStmt s | s.getExpr() = e) and + not exists(ForStmt for | for.getUpdate() = e) and message = "Use of an assignment operator's result." } diff --git a/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected index 3f2720dd76..d24fa22114 100644 --- a/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected +++ b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected @@ -1,3 +1,4 @@ | test.cpp:9:7:9:12 | ... = ... | Use of an assignment operator's result. | | test.cpp:13:11:13:16 | ... = ... | Use of an assignment operator's result. | | test.cpp:15:8:15:13 | ... = ... | Use of an assignment operator's result. | +| test.cpp:17:6:17:13 | ... += ... | Use of an assignment operator's result. | diff --git a/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp index 21fb4c0910..0e04d3a7f1 100644 --- a/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp +++ b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp @@ -13,4 +13,15 @@ void test() { l1 = l3[l2 = 0]; // NON_COMPLIANT l1 = l2 = 0; // NON_COMPLIANT -} \ No newline at end of file + + l3[l1 += l2] = l3[l1]; // NON_COMPLIANT + + for (l1 = 0; l1 < 10; l1 += l2) // COMPLIANT + { + } + + while (l1 < 10) // COMPLIANT + { + l1 += l2; // COMPLIANT + } +}