Skip to content

Commit 13feea8

Browse files
committed
Create rule files
1 parent 05d577f commit 13feea8

8 files changed

+91
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @id c/misra/ctype-function-arg-not-unsigned-char-or-eof
3+
* @name RULE-21-13: <ctype.h> function arguments shall be represented as unsigned char
4+
* @description Passing arguments to <ctype.h> functions outside the range of unsigned char or EOF
5+
* causes undefined behavior.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-21-13
10+
* external/misra/obligation/mandatory
11+
*/
12+
13+
import cpp
14+
import codingstandards.c.misra
15+
16+
from
17+
where
18+
not isExcluded(x, StandardLibraryFunctionTypesPackage::ctypeFunctionArgNotUnsignedCharOrEofQuery()) and
19+
select
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @id c/misra/memcpy-memmove-memcmp-arg-not-pointers-to-compatible-types
3+
* @name RULE-21-15: The pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers
4+
* @description Passing pointers to incompatible types as arguments to memcpy, memmove and memcmp
5+
* indicates programmers' confusion.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-21-15
10+
* external/misra/obligation/required
11+
*/
12+
13+
import cpp
14+
import codingstandards.c.misra
15+
16+
from
17+
where
18+
not isExcluded(x, StandardLibraryFunctionTypesPackage::memcpyMemmoveMemcmpArgNotPointersToCompatibleTypesQuery()) and
19+
select
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-21-13/CtypeFunctionArgNotUnsignedCharOrEof.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-21-15/MemcpyMemmoveMemcmpArgNotPointersToCompatibleTypes.ql

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Preprocessor5
4242
import Preprocessor6
4343
import SideEffects1
4444
import SideEffects2
45+
import StandardLibraryFunctionTypes
4546
import Strings1
4647
import Strings2
4748
import Strings3
@@ -89,6 +90,7 @@ newtype TCQuery =
8990
TPreprocessor6PackageQuery(Preprocessor6Query q) or
9091
TSideEffects1PackageQuery(SideEffects1Query q) or
9192
TSideEffects2PackageQuery(SideEffects2Query q) or
93+
TStandardLibraryFunctionTypesPackageQuery(StandardLibraryFunctionTypesQuery q) or
9294
TStrings1PackageQuery(Strings1Query q) or
9395
TStrings2PackageQuery(Strings2Query q) or
9496
TStrings3PackageQuery(Strings3Query q) or
@@ -136,6 +138,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
136138
isPreprocessor6QueryMetadata(query, queryId, ruleId, category) or
137139
isSideEffects1QueryMetadata(query, queryId, ruleId, category) or
138140
isSideEffects2QueryMetadata(query, queryId, ruleId, category) or
141+
isStandardLibraryFunctionTypesQueryMetadata(query, queryId, ruleId, category) or
139142
isStrings1QueryMetadata(query, queryId, ruleId, category) or
140143
isStrings2QueryMetadata(query, queryId, ruleId, category) or
141144
isStrings3QueryMetadata(query, queryId, ruleId, category) or
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype StandardLibraryFunctionTypesQuery =
7+
TCtypeFunctionArgNotUnsignedCharOrEofQuery() or
8+
TMemcpyMemmoveMemcmpArgNotPointersToCompatibleTypesQuery()
9+
10+
predicate isStandardLibraryFunctionTypesQueryMetadata(
11+
Query query, string queryId, string ruleId, string category
12+
) {
13+
query =
14+
// `Query` instance for the `ctypeFunctionArgNotUnsignedCharOrEof` query
15+
StandardLibraryFunctionTypesPackage::ctypeFunctionArgNotUnsignedCharOrEofQuery() and
16+
queryId =
17+
// `@id` for the `ctypeFunctionArgNotUnsignedCharOrEof` query
18+
"c/misra/ctype-function-arg-not-unsigned-char-or-eof" and
19+
ruleId = "RULE-21-13" and
20+
category = "mandatory"
21+
or
22+
query =
23+
// `Query` instance for the `memcpyMemmoveMemcmpArgNotPointersToCompatibleTypes` query
24+
StandardLibraryFunctionTypesPackage::memcpyMemmoveMemcmpArgNotPointersToCompatibleTypesQuery() and
25+
queryId =
26+
// `@id` for the `memcpyMemmoveMemcmpArgNotPointersToCompatibleTypes` query
27+
"c/misra/memcpy-memmove-memcmp-arg-not-pointers-to-compatible-types" and
28+
ruleId = "RULE-21-15" and
29+
category = "required"
30+
}
31+
32+
module StandardLibraryFunctionTypesPackage {
33+
Query ctypeFunctionArgNotUnsignedCharOrEofQuery() {
34+
//autogenerate `Query` type
35+
result =
36+
// `Query` type for `ctypeFunctionArgNotUnsignedCharOrEof` query
37+
TQueryC(TStandardLibraryFunctionTypesPackageQuery(TCtypeFunctionArgNotUnsignedCharOrEofQuery()))
38+
}
39+
40+
Query memcpyMemmoveMemcmpArgNotPointersToCompatibleTypesQuery() {
41+
//autogenerate `Query` type
42+
result =
43+
// `Query` type for `memcpyMemmoveMemcmpArgNotPointersToCompatibleTypes` query
44+
TQueryC(TStandardLibraryFunctionTypesPackageQuery(TMemcpyMemmoveMemcmpArgNotPointersToCompatibleTypesQuery()))
45+
}
46+
}

0 commit comments

Comments
 (0)