Skip to content

Commit e0e4181

Browse files
author
Nikita Kraiouchkine
committed
Add Pointers3 package
Add rule definition and package files Add Pointers3 to package list in tasks.json
1 parent 8462844 commit e0e4181

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
"Pointers",
234234
"Pointers1",
235235
"Pointers2",
236+
"Pointers3",
236237
"Scope",
237238
"SideEffects1",
238239
"SideEffects2",
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Pointers3Query =
7+
TDoNotAccessVolatileObjectWithNonVolatileReferenceQuery() or
8+
TDoNotCastPointerToMoreStrictlyAlignedPointerTypeQuery() or
9+
TDoNotAccessVariableViaPointerOfIncompatibleTypeQuery() or
10+
TUndefinedBehaviorWithRestrictQualifiedPointersQuery()
11+
12+
predicate isPointers3QueryMetadata(Query query, string queryId, string ruleId) {
13+
query =
14+
// `Query` instance for the `doNotAccessVolatileObjectWithNonVolatileReference` query
15+
Pointers3Package::doNotAccessVolatileObjectWithNonVolatileReferenceQuery() and
16+
queryId =
17+
// `@id` for the `doNotAccessVolatileObjectWithNonVolatileReference` query
18+
"c/cert/do-not-access-volatile-object-with-non-volatile-reference" and
19+
ruleId = "EXP32-C"
20+
or
21+
query =
22+
// `Query` instance for the `doNotCastPointerToMoreStrictlyAlignedPointerType` query
23+
Pointers3Package::doNotCastPointerToMoreStrictlyAlignedPointerTypeQuery() and
24+
queryId =
25+
// `@id` for the `doNotCastPointerToMoreStrictlyAlignedPointerType` query
26+
"c/cert/do-not-cast-pointer-to-more-strictly-aligned-pointer-type" and
27+
ruleId = "EXP36-C"
28+
or
29+
query =
30+
// `Query` instance for the `doNotAccessVariableViaPointerOfIncompatibleType` query
31+
Pointers3Package::doNotAccessVariableViaPointerOfIncompatibleTypeQuery() and
32+
queryId =
33+
// `@id` for the `doNotAccessVariableViaPointerOfIncompatibleType` query
34+
"c/cert/do-not-access-variable-via-pointer-of-incompatible-type" and
35+
ruleId = "EXP39-C"
36+
or
37+
query =
38+
// `Query` instance for the `undefinedBehaviorWithRestrictQualifiedPointers` query
39+
Pointers3Package::undefinedBehaviorWithRestrictQualifiedPointersQuery() and
40+
queryId =
41+
// `@id` for the `undefinedBehaviorWithRestrictQualifiedPointers` query
42+
"c/cert/undefined-behavior-with-restrict-qualified-pointers" and
43+
ruleId = "EXP43-C"
44+
}
45+
46+
module Pointers3Package {
47+
Query doNotAccessVolatileObjectWithNonVolatileReferenceQuery() {
48+
//autogenerate `Query` type
49+
result =
50+
// `Query` type for `doNotAccessVolatileObjectWithNonVolatileReference` query
51+
TQueryC(TPointers3PackageQuery(TDoNotAccessVolatileObjectWithNonVolatileReferenceQuery()))
52+
}
53+
54+
Query doNotCastPointerToMoreStrictlyAlignedPointerTypeQuery() {
55+
//autogenerate `Query` type
56+
result =
57+
// `Query` type for `doNotCastPointerToMoreStrictlyAlignedPointerType` query
58+
TQueryC(TPointers3PackageQuery(TDoNotCastPointerToMoreStrictlyAlignedPointerTypeQuery()))
59+
}
60+
61+
Query doNotAccessVariableViaPointerOfIncompatibleTypeQuery() {
62+
//autogenerate `Query` type
63+
result =
64+
// `Query` type for `doNotAccessVariableViaPointerOfIncompatibleType` query
65+
TQueryC(TPointers3PackageQuery(TDoNotAccessVariableViaPointerOfIncompatibleTypeQuery()))
66+
}
67+
68+
Query undefinedBehaviorWithRestrictQualifiedPointersQuery() {
69+
//autogenerate `Query` type
70+
result =
71+
// `Query` type for `undefinedBehaviorWithRestrictQualifiedPointers` query
72+
TQueryC(TPointers3PackageQuery(TUndefinedBehaviorWithRestrictQualifiedPointersQuery()))
73+
}
74+
}

cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Language1
2424
import Misc
2525
import Pointers1
2626
import Pointers2
27+
import Pointers3
2728
import Preprocessor1
2829
import Preprocessor2
2930
import Preprocessor3
@@ -60,6 +61,7 @@ newtype TCQuery =
6061
TMiscPackageQuery(MiscQuery q) or
6162
TPointers1PackageQuery(Pointers1Query q) or
6263
TPointers2PackageQuery(Pointers2Query q) or
64+
TPointers3PackageQuery(Pointers3Query q) or
6365
TPreprocessor1PackageQuery(Preprocessor1Query q) or
6466
TPreprocessor2PackageQuery(Preprocessor2Query q) or
6567
TPreprocessor3PackageQuery(Preprocessor3Query q) or
@@ -96,6 +98,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId) {
9698
isMiscQueryMetadata(query, queryId, ruleId) or
9799
isPointers1QueryMetadata(query, queryId, ruleId) or
98100
isPointers2QueryMetadata(query, queryId, ruleId) or
101+
isPointers3QueryMetadata(query, queryId, ruleId) or
99102
isPreprocessor1QueryMetadata(query, queryId, ruleId) or
100103
isPreprocessor2QueryMetadata(query, queryId, ruleId) or
101104
isPreprocessor3QueryMetadata(query, queryId, ruleId) or

rule_packages/c/Pointers3.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"CERT-C": {
3+
"EXP32-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "If an an object defined with a volatile-qualified type is referred to with an lvalue of a non-volatile-qualified type, the behavior is undefined.",
10+
"kind": "problem",
11+
"name": "Do not access a volatile object through a nonvolatile reference",
12+
"precision": "high",
13+
"severity": "error",
14+
"short_name": "DoNotAccessVolatileObjectWithNonVolatileReference",
15+
"tags": [
16+
"correctness"
17+
]
18+
}
19+
],
20+
"title": "Do not access a volatile object through a nonvolatile reference"
21+
},
22+
"EXP36-C": {
23+
"properties": {
24+
"obligation": "rule"
25+
},
26+
"queries": [
27+
{
28+
"description": "Converting a pointer to a different type results in undefined behavior if the pointer is not correctly aligned for the new type.",
29+
"kind": "path-problem",
30+
"name": "Do not cast pointers into more strictly aligned pointer types",
31+
"precision": "high",
32+
"severity": "error",
33+
"short_name": "DoNotCastPointerToMoreStrictlyAlignedPointerType",
34+
"tags": [
35+
"correctness"
36+
]
37+
}
38+
],
39+
"title": "Do not cast pointers into more strictly aligned pointer types"
40+
},
41+
"EXP39-C": {
42+
"properties": {
43+
"obligation": "rule"
44+
},
45+
"queries": [
46+
{
47+
"description": "Modifying underlying pointer data through a pointer of an incompatible type can lead to unpredictable results.",
48+
"kind": "problem",
49+
"name": "Do not access a variable through a pointer of an incompatible type",
50+
"precision": "very-high",
51+
"severity": "error",
52+
"short_name": "DoNotAccessVariableViaPointerOfIncompatibleType",
53+
"tags": [
54+
"correctness"
55+
]
56+
}
57+
],
58+
"title": "Do not access a variable through a pointer of an incompatible type"
59+
},
60+
"EXP43-C": {
61+
"properties": {
62+
"obligation": "rule"
63+
},
64+
"queries": [
65+
{
66+
"description": "",
67+
"kind": "problem",
68+
"name": "Avoid undefined behavior when using restrict-qualified pointers",
69+
"precision": "very-high",
70+
"severity": "error",
71+
"short_name": "UndefinedBehaviorWithRestrictQualifiedPointers",
72+
"tags": [
73+
"correctness"
74+
]
75+
}
76+
],
77+
"title": "Avoid undefined behavior when using restrict-qualified pointers"
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)