From 36092b7fde83319d4c62a51cd844e42afbf21cc7 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Mon, 18 May 2026 22:12:29 +0200 Subject: [PATCH 1/4] Fix FP for MISRA-C RULE-13-4 --- ...ltOfAnAssignmentOperatorShouldNotBeUsed.expected | 1 + .../test.c | 11 +++++++++++ change_notes/2026-05-18-fix-fp-misra-c-13-4.md | 4 ++++ .../ResultOfAnAssignmentOperatorShouldNotBeUsed.qll | 3 ++- .../test.cpp | 13 ++++++++++++- 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 change_notes/2026-05-18-fix-fp-misra-c-13-4.md 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..ddf5b9e14b --- /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. +- `RULE-8-18-2` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: + - Fixed false positives. 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/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 + } +} From 0bde887cb312766fcffc76181a96b5e136290779 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 20:26:43 +0000 Subject: [PATCH 2/4] Update change note for compound-assignment coverage --- change_notes/2026-05-18-fix-fp-misra-c-13-4.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index ddf5b9e14b..bfdcb980ca 100644 --- 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 @@ -1,4 +1,4 @@ - `RULE-13-4` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: - - Fixed false positives. + - Fixed false positives and false negatives by reporting compound assignments (for example, `+=`). - `RULE-8-18-2` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: - - Fixed false positives. + - Fixed false positives and false negatives by reporting compound assignments (for example, `+=`). From 1ef9a6f47265d8619f088880bd29aa2510ddbd99 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Mon, 18 May 2026 22:31:06 +0200 Subject: [PATCH 3/4] Update 2026-05-18-fix-fp-misra-c-13-4.md --- change_notes/2026-05-18-fix-fp-misra-c-13-4.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index bfdcb980ca..bf6b7c1313 100644 --- 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 @@ -1,4 +1,4 @@ - `RULE-13-4` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: - - Fixed false positives and false negatives by reporting compound assignments (for example, `+=`). + - Fixed false positives and false negatives. - `RULE-8-18-2` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`: - - Fixed false positives and false negatives by reporting compound assignments (for example, `+=`). + - Fixed false positives and false negatives. From 66d73d5c679299876ac8363d07aaf318dde4d492 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Tue, 19 May 2026 01:07:11 +0200 Subject: [PATCH 4/4] fix expected file --- .../ResultOfAnAssignmentOperatorShouldNotBeUsed.expected | 1 + 1 file changed, 1 insertion(+) 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. |