From d7137ec81be18ee65f8e9e7297dc3afe0ded5e79 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 18 Jun 2026 15:03:49 +0200 Subject: [PATCH 1/4] Add compliance tests for division and modulus operations in unsigned operations --- .../unsignedoperationwithconstantoperandswraps/test.c | 7 +++++++ change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md | 4 ++++ .../UnsignedOperationWithConstantOperandsWraps.qll | 3 +-- .../unsignedoperationwithconstantoperandswraps/test.cpp | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md diff --git a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c index 214b18a44f..e5dbdc1265 100644 --- a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c +++ b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c @@ -80,4 +80,11 @@ void test_sub_postcheck(unsigned int i1, unsigned int i2) { if (i1 > i2) { // handle error } + + void test_mod_rem(unsigned int i1, unsigned int i2) { + i1 / i2; // COMPLIANT - exception 2 + i1 /= i2; // COMPLIANT - exception 2 + i1 % i2; // COMPLIANT - exception 2 + i1 %= i2; // COMPLIANT - exception 2 + } } \ No newline at end of file diff --git a/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md b/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md new file mode 100644 index 0000000000..3ee9bcde40 --- /dev/null +++ b/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md @@ -0,0 +1,4 @@ +- `INT30-C` - `UnsignedIntegerOperationsWrapAround.ql`: + - Fixed false positives for `/=` and `%=` assignments. +- `INT30-C` - `UnsignedOperationWithConstantOperandsWraps.ql`: + - Fixed false positives for `/=` and `%=` assignments. diff --git a/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll b/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll index bc0c6d8fc1..06f4cb0868 100644 --- a/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll +++ b/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll @@ -26,8 +26,7 @@ query predicate problems(InterestingOverflowingOperation op, string message) { // Permitted by exception 3 not op instanceof LShiftExpr and // Permitted by exception 2 - zero case is handled in separate query - not op instanceof DivExpr and - not op instanceof RemExpr and + not op instanceof DivOrRemOperation and message = "Operation " + op.getOperator() + " of type " + op.getType().getUnderlyingType() + " may wrap." } diff --git a/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp index 8f76fbeeeb..86ac7645bf 100644 --- a/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp +++ b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp @@ -80,4 +80,11 @@ void test_sub_postcheck(unsigned int i1, unsigned int i2) { if (i1 > i2) { // handle error } + + void test_mod_rem(unsigned int i1, unsigned int i2) { + i1 / i2; // COMPLIANT - exception 2 + i1 /= i2; // COMPLIANT - exception 2 + i1 % i2; // COMPLIANT - exception 2 + i1 %= i2; // COMPLIANT - exception 2 + } } \ No newline at end of file From 4bce35a06d26b9bbeef1a57aba11fcf37b653546 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 18 Jun 2026 15:13:45 +0200 Subject: [PATCH 2/4] Fix rule identifier for UnsignedOperationWithConstantOperandsWraps.ql in change notes --- change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md b/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md index 3ee9bcde40..55bfb0f213 100644 --- a/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md +++ b/change_notes/2026-06-18-fix-fp-misra-c++-8-20-1.md @@ -1,4 +1,4 @@ - `INT30-C` - `UnsignedIntegerOperationsWrapAround.ql`: - Fixed false positives for `/=` and `%=` assignments. -- `INT30-C` - `UnsignedOperationWithConstantOperandsWraps.ql`: +- `RULE-8-20-1` - `UnsignedOperationWithConstantOperandsWraps.ql`: - Fixed false positives for `/=` and `%=` assignments. From 397325d1181c4920d9b77c67ffdb7f9da4011934 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 18 Jun 2026 15:24:28 +0200 Subject: [PATCH 3/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp index 86ac7645bf..31a561cdbf 100644 --- a/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp +++ b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp @@ -80,11 +80,11 @@ void test_sub_postcheck(unsigned int i1, unsigned int i2) { if (i1 > i2) { // handle error } +} - void test_mod_rem(unsigned int i1, unsigned int i2) { - i1 / i2; // COMPLIANT - exception 2 - i1 /= i2; // COMPLIANT - exception 2 - i1 % i2; // COMPLIANT - exception 2 - i1 %= i2; // COMPLIANT - exception 2 - } +void test_mod_rem(unsigned int i1, unsigned int i2) { + i1 / i2; // COMPLIANT - exception 2 + i1 /= i2; // COMPLIANT - exception 2 + i1 % i2; // COMPLIANT - exception 2 + i1 %= i2; // COMPLIANT - exception 2 } \ No newline at end of file From d480f615606dc3d331e7ca73b4edd2b7db2ca715 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 18 Jun 2026 15:24:37 +0200 Subject: [PATCH 4/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c index e5dbdc1265..05afe496a6 100644 --- a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c +++ b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c @@ -80,11 +80,11 @@ void test_sub_postcheck(unsigned int i1, unsigned int i2) { if (i1 > i2) { // handle error } +} - void test_mod_rem(unsigned int i1, unsigned int i2) { - i1 / i2; // COMPLIANT - exception 2 - i1 /= i2; // COMPLIANT - exception 2 - i1 % i2; // COMPLIANT - exception 2 - i1 %= i2; // COMPLIANT - exception 2 - } +void test_mod_rem(unsigned int i1, unsigned int i2) { + i1 / i2; // COMPLIANT - exception 2 + i1 /= i2; // COMPLIANT - exception 2 + i1 % i2; // COMPLIANT - exception 2 + i1 %= i2; // COMPLIANT - exception 2 } \ No newline at end of file