From df95b6cb0a6a0761e74e0d5ed9607cc4baa583d7 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Fri, 30 Jan 2026 15:05:09 -0500 Subject: [PATCH 1/8] Check in rule description files --- .../cpp/exclusions/cpp/Memory2.qll | 26 +++++++++++++++++++ .../cpp/exclusions/cpp/RuleMetadata.qll | 3 +++ ...erDifferenceTakenBetweenDifferentArrays.ql | 20 ++++++++++++++ ...erenceTakenBetweenDifferentArrays.expected | 1 + ...ifferenceTakenBetweenDifferentArrays.qlref | 1 + rule_packages/cpp/Memory2.json | 24 +++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory2.qll create mode 100644 cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql create mode 100644 cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected create mode 100644 cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref create mode 100644 rule_packages/cpp/Memory2.json diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory2.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory2.qll new file mode 100644 index 0000000000..d7bfbba99e --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory2.qll @@ -0,0 +1,26 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype Memory2Query = TPointerDifferenceTakenBetweenDifferentArraysQuery() + +predicate isMemory2QueryMetadata(Query query, string queryId, string ruleId, string category) { + query = + // `Query` instance for the `pointerDifferenceTakenBetweenDifferentArrays` query + Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery() and + queryId = + // `@id` for the `pointerDifferenceTakenBetweenDifferentArrays` query + "cpp/misra/pointer-difference-taken-between-different-arrays" and + ruleId = "RULE-8-7-2" and + category = "required" +} + +module Memory2Package { + Query pointerDifferenceTakenBetweenDifferentArraysQuery() { + //autogenerate `Query` type + result = + // `Query` type for `pointerDifferenceTakenBetweenDifferentArrays` query + TQueryCPP(TMemory2PackageQuery(TPointerDifferenceTakenBetweenDifferentArraysQuery())) + } +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll index b51bc8465c..c7fdb0e0da 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll @@ -40,6 +40,7 @@ import Linkage2 import Literals import Loops import Macros +import Memory2 import MoveForward import Naming import Null @@ -105,6 +106,7 @@ newtype TCPPQuery = TLiteralsPackageQuery(LiteralsQuery q) or TLoopsPackageQuery(LoopsQuery q) or TMacrosPackageQuery(MacrosQuery q) or + TMemory2PackageQuery(Memory2Query q) or TMoveForwardPackageQuery(MoveForwardQuery q) or TNamingPackageQuery(NamingQuery q) or TNullPackageQuery(NullQuery q) or @@ -170,6 +172,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat isLiteralsQueryMetadata(query, queryId, ruleId, category) or isLoopsQueryMetadata(query, queryId, ruleId, category) or isMacrosQueryMetadata(query, queryId, ruleId, category) or + isMemory2QueryMetadata(query, queryId, ruleId, category) or isMoveForwardQueryMetadata(query, queryId, ruleId, category) or isNamingQueryMetadata(query, queryId, ruleId, category) or isNullQueryMetadata(query, queryId, ruleId, category) or diff --git a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql new file mode 100644 index 0000000000..f1d63caca5 --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql @@ -0,0 +1,20 @@ +/** + * @id cpp/misra/pointer-difference-taken-between-different-arrays + * @name RULE-8-7-2: Subtraction between pointers shall only be applied to ones that address elements of the same array + * @description Pointer difference should be taken from pointers that belong to a same array. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-7-2 + * scope/system + * external/misra/enforcement/undecidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra + +from +where + not isExcluded(x, Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery()) and +select diff --git a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected new file mode 100644 index 0000000000..2ec1a0ac6c --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected @@ -0,0 +1 @@ +No expected results have yet been specified \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref new file mode 100644 index 0000000000..052ea5cc1e --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref @@ -0,0 +1 @@ +rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql \ No newline at end of file diff --git a/rule_packages/cpp/Memory2.json b/rule_packages/cpp/Memory2.json new file mode 100644 index 0000000000..9bf5542d9d --- /dev/null +++ b/rule_packages/cpp/Memory2.json @@ -0,0 +1,24 @@ +{ + "MISRA-C++-2023": { + "RULE-8-7-2": { + "properties": { + "enforcement": "undecidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Pointer difference should be taken from pointers that belong to a same array.", + "kind": "problem", + "name": "Subtraction between pointers shall only be applied to ones that address elements of the same array", + "precision": "very-high", + "severity": "error", + "short_name": "PointerDifferenceTakenBetweenDifferentArrays", + "tags": [ + "scope/system" + ] + } + ], + "title": "Pointer difference should be taken from pointers that belong to a same array." + } + } +} From e0362b7cfc18abc8fc5bdd7e8eb8b66f90ed0d86 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Sat, 31 Jan 2026 18:20:09 -0500 Subject: [PATCH 2/8] Add Memory3 --- .../src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll | 3 +++ rules.csv | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll index c7fdb0e0da..19f143db60 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll @@ -41,6 +41,7 @@ import Literals import Loops import Macros import Memory2 +import Memory3 import MoveForward import Naming import Null @@ -107,6 +108,7 @@ newtype TCPPQuery = TLoopsPackageQuery(LoopsQuery q) or TMacrosPackageQuery(MacrosQuery q) or TMemory2PackageQuery(Memory2Query q) or + TMemory3PackageQuery(Memory3Query q) or TMoveForwardPackageQuery(MoveForwardQuery q) or TNamingPackageQuery(NamingQuery q) or TNullPackageQuery(NullQuery q) or @@ -173,6 +175,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat isLoopsQueryMetadata(query, queryId, ruleId, category) or isMacrosQueryMetadata(query, queryId, ruleId, category) or isMemory2QueryMetadata(query, queryId, ruleId, category) or + isMemory3QueryMetadata(query, queryId, ruleId, category) or isMoveForwardQueryMetadata(query, queryId, ruleId, category) or isNamingQueryMetadata(query, queryId, ruleId, category) or isNullQueryMetadata(query, queryId, ruleId, category) or diff --git a/rules.csv b/rules.csv index cca308583d..3011924c82 100644 --- a/rules.csv +++ b/rules.csv @@ -895,9 +895,9 @@ cpp,MISRA-C++-2023,RULE-8-2-10,Yes,Required,Undecidable,System,"Functions shall cpp,MISRA-C++-2023,RULE-8-2-11,Yes,Required,Decidable,Single Translation Unit,An argument passed via ellipsis shall have an appropriate type,,Preconditions,Easy, cpp,MISRA-C++-2023,RULE-8-3-1,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary - operator should not be applied to an expression of unsigned type,M5-3-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-8-3-2,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary + operator should not be used,,Banned,Easy, -cpp,MISRA-C++-2023,RULE-8-7-1,Yes,Required,Undecidable,System,Pointer arithmetic shall not form an invalid pointer,ARR30-C,Memory,Easy, -cpp,MISRA-C++-2023,RULE-8-7-2,Yes,Required,Undecidable,System,Subtraction between pointers shall only be applied to pointers that address elements of the same array,ARR36-C,Memory,Easy, -cpp,MISRA-C++-2023,RULE-8-9-1,Yes,Required,Undecidable,System,"The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array",ARR36-C,Memory,Easy, +cpp,MISRA-C++-2023,RULE-8-7-1,Yes,Required,Undecidable,System,Pointer arithmetic shall not form an invalid pointer,ARR30-C,Memory1,Easy, +cpp,MISRA-C++-2023,RULE-8-7-2,Yes,Required,Undecidable,System,Subtraction between pointers shall only be applied to pointers that address elements of the same array,ARR36-C,Memory2,Easy, +cpp,MISRA-C++-2023,RULE-8-9-1,Yes,Required,Undecidable,System,"The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array",ARR36-C,Memory3,Easy, cpp,MISRA-C++-2023,RULE-8-14-1,Yes,Advisory,Undecidable,System,The right-hand operand of a logical && or operator should not contain persistent side effects,"M5-14-1, RULE-13-5",SideEffects3,Medium, cpp,MISRA-C++-2023,RULE-8-18-1,Yes,Mandatory,Undecidable,System,An object or subobject must not be copied to an overlapping object,"M0-2-1, RULE-19-1",Memory,Hard, cpp,MISRA-C++-2023,RULE-8-18-2,Yes,Advisory,Decidable,Single Translation Unit,The result of an assignment operator should not be used,RULE-13-4,ImportMisra23,Import, From f0a776479a9798c3241554459c14682516acfaec Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 2 Feb 2026 13:39:21 -0500 Subject: [PATCH 3/8] Add "shared_implementation_short_name" and check in all files --- .../cpp/exclusions/cpp/Memory3.qll | 26 +++++++++++++++++++ .../PointerComparedBetweenDifferentArrays.ql | 23 ++++++++++++++++ ...terComparedBetweenDifferentArrays.expected | 1 + ...ointerComparedBetweenDifferentArrays.qlref | 1 + rule_packages/cpp/Memory2.json | 1 + rule_packages/cpp/Memory3.json | 26 +++++++++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory3.qll create mode 100644 cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql create mode 100644 cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected create mode 100644 cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref create mode 100644 rule_packages/cpp/Memory3.json diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory3.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory3.qll new file mode 100644 index 0000000000..6dce95e89e --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory3.qll @@ -0,0 +1,26 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype Memory3Query = TPointerComparedBetweenDifferentArraysQuery() + +predicate isMemory3QueryMetadata(Query query, string queryId, string ruleId, string category) { + query = + // `Query` instance for the `pointerComparedBetweenDifferentArrays` query + Memory3Package::pointerComparedBetweenDifferentArraysQuery() and + queryId = + // `@id` for the `pointerComparedBetweenDifferentArrays` query + "cpp/misra/pointer-compared-between-different-arrays" and + ruleId = "RULE-8-9-1" and + category = "required" +} + +module Memory3Package { + Query pointerComparedBetweenDifferentArraysQuery() { + //autogenerate `Query` type + result = + // `Query` type for `pointerComparedBetweenDifferentArrays` query + TQueryCPP(TMemory3PackageQuery(TPointerComparedBetweenDifferentArraysQuery())) + } +} diff --git a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql new file mode 100644 index 0000000000..e0ffc6403a --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/pointer-compared-between-different-arrays + * @name RULE-8-9-1: The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type + * @description Pointer comparison should be done between ones that belong to a same array. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-9-1 + * scope/system + * external/misra/enforcement/undecidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.donotuserelationaloperatorswithdifferingarrays.DoNotUseRelationalOperatorsWithDifferingArrays + +class PointerComparedBetweenDifferentArraysQuery extends DoNotUseRelationalOperatorsWithDifferingArraysSharedQuery +{ + PointerComparedBetweenDifferentArraysQuery() { + this = Memory3Package::pointerComparedBetweenDifferentArraysQuery() + } +} diff --git a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected new file mode 100644 index 0000000000..2ec1a0ac6c --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected @@ -0,0 +1 @@ +No expected results have yet been specified \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref new file mode 100644 index 0000000000..4caeb41eb1 --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref @@ -0,0 +1 @@ +rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql \ No newline at end of file diff --git a/rule_packages/cpp/Memory2.json b/rule_packages/cpp/Memory2.json index 9bf5542d9d..ebf4e7a846 100644 --- a/rule_packages/cpp/Memory2.json +++ b/rule_packages/cpp/Memory2.json @@ -13,6 +13,7 @@ "precision": "very-high", "severity": "error", "short_name": "PointerDifferenceTakenBetweenDifferentArrays", + "shared_implementation_short_name": "DoNotSubtractPointersAddressingDifferentArrays", "tags": [ "scope/system" ] diff --git a/rule_packages/cpp/Memory3.json b/rule_packages/cpp/Memory3.json new file mode 100644 index 0000000000..4ef1aa91a3 --- /dev/null +++ b/rule_packages/cpp/Memory3.json @@ -0,0 +1,26 @@ +{ + "MISRA-C++-2023": { + "RULE-8-9-1": { + "properties": { + "enforcement": "undecidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Pointer comparison should be done between ones that belong to a same array.", + "kind": "problem", + "name": "The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type", + "precision": "very-high", + "severity": "error", + "short_name": "PointerComparedBetweenDifferentArrays", + "shared_implementation_short_name": "DoNotUseRelationalOperatorsWithDifferingArrays", + "shared_implementation_short_name": "", + "tags": [ + "scope/system" + ] + } + ], + "title": "Pointer comparison should be done between ones that belong to a same array." + } + } +} From a3525b8c1ed1af9853e4a98dbae30c1a82639b77 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 2 Feb 2026 15:44:12 -0500 Subject: [PATCH 4/8] Re-add package files --- .../PointerDifferenceTakenBetweenDifferentArrays.ql | 13 ++++++++----- .../PointerComparedBetweenDifferentArrays.ql | 2 +- ...terDifferenceTakenBetweenDifferentArrays.testref | 1 + .../PointerComparedBetweenDifferentArrays.testref | 1 + rule_packages/cpp/Memory2.json | 2 +- rule_packages/cpp/Memory3.json | 3 +-- 6 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.testref create mode 100644 cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref diff --git a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql index f1d63caca5..a7f966d6a5 100644 --- a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql +++ b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql @@ -3,7 +3,7 @@ * @name RULE-8-7-2: Subtraction between pointers shall only be applied to ones that address elements of the same array * @description Pointer difference should be taken from pointers that belong to a same array. * @kind problem - * @precision very-high + * @precision high * @problem.severity error * @tags external/misra/id/rule-8-7-2 * scope/system @@ -13,8 +13,11 @@ import cpp import codingstandards.cpp.misra +import codingstandards.cpp.rules.donotsubtractpointersaddressingdifferentarrays.DoNotSubtractPointersAddressingDifferentArrays -from -where - not isExcluded(x, Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery()) and -select +class PointerDifferenceTakenBetweenDifferentArraysQuery extends DoNotSubtractPointersAddressingDifferentArraysSharedQuery +{ + PointerDifferenceTakenBetweenDifferentArraysQuery() { + this = Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql index e0ffc6403a..7d98dffa7b 100644 --- a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql +++ b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql @@ -3,7 +3,7 @@ * @name RULE-8-9-1: The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type * @description Pointer comparison should be done between ones that belong to a same array. * @kind problem - * @precision very-high + * @precision high * @problem.severity error * @tags external/misra/id/rule-8-9-1 * scope/system diff --git a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.testref b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.testref new file mode 100644 index 0000000000..6506d7bed1 --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.testref @@ -0,0 +1 @@ +cpp/common/test/rules/donotsubtractpointersaddressingdifferentarrays/DoNotSubtractPointersAddressingDifferentArrays.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref new file mode 100644 index 0000000000..6fb4484df5 --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref @@ -0,0 +1 @@ +cpp/common/test/rules/.ql \ No newline at end of file diff --git a/rule_packages/cpp/Memory2.json b/rule_packages/cpp/Memory2.json index ebf4e7a846..e0800b018f 100644 --- a/rule_packages/cpp/Memory2.json +++ b/rule_packages/cpp/Memory2.json @@ -10,7 +10,7 @@ "description": "Pointer difference should be taken from pointers that belong to a same array.", "kind": "problem", "name": "Subtraction between pointers shall only be applied to ones that address elements of the same array", - "precision": "very-high", + "precision": "high", "severity": "error", "short_name": "PointerDifferenceTakenBetweenDifferentArrays", "shared_implementation_short_name": "DoNotSubtractPointersAddressingDifferentArrays", diff --git a/rule_packages/cpp/Memory3.json b/rule_packages/cpp/Memory3.json index 4ef1aa91a3..33405af7b2 100644 --- a/rule_packages/cpp/Memory3.json +++ b/rule_packages/cpp/Memory3.json @@ -10,11 +10,10 @@ "description": "Pointer comparison should be done between ones that belong to a same array.", "kind": "problem", "name": "The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type", - "precision": "very-high", + "precision": "high", "severity": "error", "short_name": "PointerComparedBetweenDifferentArrays", "shared_implementation_short_name": "DoNotUseRelationalOperatorsWithDifferingArrays", - "shared_implementation_short_name": "", "tags": [ "scope/system" ] From a30e93c6c68522fff75020d64b254edb969eac54 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 2 Feb 2026 15:53:11 -0500 Subject: [PATCH 5/8] Fix @kind metadata property --- .../RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql | 2 +- .../rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql | 2 +- rule_packages/cpp/Memory2.json | 2 +- rule_packages/cpp/Memory3.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql index a7f966d6a5..406a0685be 100644 --- a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql +++ b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql @@ -2,7 +2,7 @@ * @id cpp/misra/pointer-difference-taken-between-different-arrays * @name RULE-8-7-2: Subtraction between pointers shall only be applied to ones that address elements of the same array * @description Pointer difference should be taken from pointers that belong to a same array. - * @kind problem + * @kind path-problem * @precision high * @problem.severity error * @tags external/misra/id/rule-8-7-2 diff --git a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql index 7d98dffa7b..7093924521 100644 --- a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql +++ b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql @@ -2,7 +2,7 @@ * @id cpp/misra/pointer-compared-between-different-arrays * @name RULE-8-9-1: The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type * @description Pointer comparison should be done between ones that belong to a same array. - * @kind problem + * @kind path-problem * @precision high * @problem.severity error * @tags external/misra/id/rule-8-9-1 diff --git a/rule_packages/cpp/Memory2.json b/rule_packages/cpp/Memory2.json index e0800b018f..640ecbc6ef 100644 --- a/rule_packages/cpp/Memory2.json +++ b/rule_packages/cpp/Memory2.json @@ -8,7 +8,7 @@ "queries": [ { "description": "Pointer difference should be taken from pointers that belong to a same array.", - "kind": "problem", + "kind": "path-problem", "name": "Subtraction between pointers shall only be applied to ones that address elements of the same array", "precision": "high", "severity": "error", diff --git a/rule_packages/cpp/Memory3.json b/rule_packages/cpp/Memory3.json index 33405af7b2..d116853602 100644 --- a/rule_packages/cpp/Memory3.json +++ b/rule_packages/cpp/Memory3.json @@ -8,7 +8,7 @@ "queries": [ { "description": "Pointer comparison should be done between ones that belong to a same array.", - "kind": "problem", + "kind": "path-problem", "name": "The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type", "precision": "high", "severity": "error", From ad8864f7421f7cc12c786d2f033f21fdfa8c4445 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Mon, 2 Feb 2026 18:07:58 -0500 Subject: [PATCH 6/8] Fix the path in PointerComparedBetweenDifferentArrays.testref --- .../RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref index 6fb4484df5..5ca71e38c8 100644 --- a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref +++ b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.testref @@ -1 +1 @@ -cpp/common/test/rules/.ql \ No newline at end of file +cpp/common/test/rules/donotuserelationaloperatorswithdifferingarrays/DoNotUseRelationalOperatorsWithDifferingArrays.ql \ No newline at end of file From c8840db755112c2cf932a44347436a44db51020c Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 3 Feb 2026 10:49:32 -0500 Subject: [PATCH 7/8] Remove unneeded qlref and ql code --- .../PointerDifferenceTakenBetweenDifferentArrays.expected | 1 - .../PointerDifferenceTakenBetweenDifferentArrays.qlref | 1 - .../RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected | 1 - .../rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref | 1 - 4 files changed, 4 deletions(-) delete mode 100644 cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected delete mode 100644 cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref delete mode 100644 cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected delete mode 100644 cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref diff --git a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected deleted file mode 100644 index 2ec1a0ac6c..0000000000 --- a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.expected +++ /dev/null @@ -1 +0,0 @@ -No expected results have yet been specified \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref b/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref deleted file mode 100644 index 052ea5cc1e..0000000000 --- a/cpp/misra/test/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected deleted file mode 100644 index 2ec1a0ac6c..0000000000 --- a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.expected +++ /dev/null @@ -1 +0,0 @@ -No expected results have yet been specified \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref b/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref deleted file mode 100644 index 4caeb41eb1..0000000000 --- a/cpp/misra/test/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql \ No newline at end of file From 017f019a0ccebcfb40c2d2379aac25da9dc38801 Mon Sep 17 00:00:00 2001 From: Jeongsoo Lee Date: Tue, 3 Feb 2026 14:45:23 -0500 Subject: [PATCH 8/8] Add 'correctness' tags to rule metadata of both queries --- .../RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql | 1 + .../rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql | 1 + rule_packages/cpp/Memory2.json | 3 ++- rule_packages/cpp/Memory3.json | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql index 406a0685be..286814510a 100644 --- a/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql +++ b/cpp/misra/src/rules/RULE-8-7-2/PointerDifferenceTakenBetweenDifferentArrays.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-7-2 * scope/system + * correctness * external/misra/enforcement/undecidable * external/misra/obligation/required */ diff --git a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql index 7093924521..19f15433fc 100644 --- a/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql +++ b/cpp/misra/src/rules/RULE-8-9-1/PointerComparedBetweenDifferentArrays.ql @@ -7,6 +7,7 @@ * @problem.severity error * @tags external/misra/id/rule-8-9-1 * scope/system + * correctness * external/misra/enforcement/undecidable * external/misra/obligation/required */ diff --git a/rule_packages/cpp/Memory2.json b/rule_packages/cpp/Memory2.json index 640ecbc6ef..f4631f67aa 100644 --- a/rule_packages/cpp/Memory2.json +++ b/rule_packages/cpp/Memory2.json @@ -15,7 +15,8 @@ "short_name": "PointerDifferenceTakenBetweenDifferentArrays", "shared_implementation_short_name": "DoNotSubtractPointersAddressingDifferentArrays", "tags": [ - "scope/system" + "scope/system", + "correctness" ] } ], diff --git a/rule_packages/cpp/Memory3.json b/rule_packages/cpp/Memory3.json index d116853602..c3f09b3508 100644 --- a/rule_packages/cpp/Memory3.json +++ b/rule_packages/cpp/Memory3.json @@ -15,7 +15,8 @@ "short_name": "PointerComparedBetweenDifferentArrays", "shared_implementation_short_name": "DoNotUseRelationalOperatorsWithDifferingArrays", "tags": [ - "scope/system" + "scope/system", + "correctness" ] } ],