Skip to content
Open
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
26 changes: 26 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory2.qll
Original file line number Diff line number Diff line change
@@ -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()))
}
}
26 changes: 26 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory3.qll
Original file line number Diff line number Diff line change
@@ -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()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import Linkage2
import Literals
import Loops
import Macros
import Memory2
import Memory3
import MoveForward
import Naming
import Null
Expand Down Expand Up @@ -105,6 +107,8 @@ newtype TCPPQuery =
TLiteralsPackageQuery(LiteralsQuery q) or
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
Expand Down Expand Up @@ -170,6 +174,8 @@ 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
isMemory3QueryMetadata(query, queryId, ruleId, category) or
isMoveForwardQueryMetadata(query, queryId, ruleId, category) or
isNamingQueryMetadata(query, queryId, ruleId, category) or
isNullQueryMetadata(query, queryId, ruleId, category) or
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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 path-problem
* @precision high
* @problem.severity error
* @tags external/misra/id/rule-8-7-2
* scope/system
* correctness
* external/misra/enforcement/undecidable
* external/misra/obligation/required
*/

import cpp
import codingstandards.cpp.misra
import codingstandards.cpp.rules.donotsubtractpointersaddressingdifferentarrays.DoNotSubtractPointersAddressingDifferentArrays

class PointerDifferenceTakenBetweenDifferentArraysQuery extends DoNotSubtractPointersAddressingDifferentArraysSharedQuery
{
PointerDifferenceTakenBetweenDifferentArraysQuery() {
this = Memory2Package::pointerDifferenceTakenBetweenDifferentArraysQuery()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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 path-problem
* @precision high
* @problem.severity error
* @tags external/misra/id/rule-8-9-1
* scope/system
* correctness
* 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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cpp/common/test/rules/donotsubtractpointersaddressingdifferentarrays/DoNotSubtractPointersAddressingDifferentArrays.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cpp/common/test/rules/donotuserelationaloperatorswithdifferingarrays/DoNotUseRelationalOperatorsWithDifferingArrays.ql
26 changes: 26 additions & 0 deletions rule_packages/cpp/Memory2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"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": "path-problem",
"name": "Subtraction between pointers shall only be applied to ones that address elements of the same array",
"precision": "high",
"severity": "error",
"short_name": "PointerDifferenceTakenBetweenDifferentArrays",
"shared_implementation_short_name": "DoNotSubtractPointersAddressingDifferentArrays",
"tags": [
"scope/system",
"correctness"
]
}
],
"title": "Pointer difference should be taken from pointers that belong to a same array."
}
}
}
26 changes: 26 additions & 0 deletions rule_packages/cpp/Memory3.json
Original file line number Diff line number Diff line change
@@ -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": "path-problem",
"name": "The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type",
"precision": "high",
"severity": "error",
"short_name": "PointerComparedBetweenDifferentArrays",
"shared_implementation_short_name": "DoNotUseRelationalOperatorsWithDifferingArrays",
"tags": [
"scope/system",
"correctness"
]
}
],
"title": "Pointer comparison should be done between ones that belong to a same array."
}
}
}
6 changes: 3 additions & 3 deletions rules.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading