Skip to content

Commit 84f007e

Browse files
committed
Contracts: add metadata.
1 parent d9f0911 commit 84f007e

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype ContractsQuery =
7+
TDoNotViolateInLineLinkageConstraintsQuery() or
8+
TCheckMathLibraryFunctionParametersQuery() or
9+
TFunctionErrorInformationUntestedQuery()
10+
11+
predicate isContractsQueryMetadata(Query query, string queryId, string ruleId, string category) {
12+
query =
13+
// `Query` instance for the `doNotViolateInLineLinkageConstraints` query
14+
ContractsPackage::doNotViolateInLineLinkageConstraintsQuery() and
15+
queryId =
16+
// `@id` for the `doNotViolateInLineLinkageConstraints` query
17+
"c/cert/do-not-violate-in-line-linkage-constraints" and
18+
ruleId = "MSC40-C" and
19+
category = "rule"
20+
or
21+
query =
22+
// `Query` instance for the `checkMathLibraryFunctionParameters` query
23+
ContractsPackage::checkMathLibraryFunctionParametersQuery() and
24+
queryId =
25+
// `@id` for the `checkMathLibraryFunctionParameters` query
26+
"c/misra/check-math-library-function-parameters" and
27+
ruleId = "DIR-4-11" and
28+
category = "required"
29+
or
30+
query =
31+
// `Query` instance for the `functionErrorInformationUntested` query
32+
ContractsPackage::functionErrorInformationUntestedQuery() and
33+
queryId =
34+
// `@id` for the `functionErrorInformationUntested` query
35+
"c/misra/function-error-information-untested" and
36+
ruleId = "DIR-4-7" and
37+
category = "required"
38+
}
39+
40+
module ContractsPackage {
41+
Query doNotViolateInLineLinkageConstraintsQuery() {
42+
//autogenerate `Query` type
43+
result =
44+
// `Query` type for `doNotViolateInLineLinkageConstraints` query
45+
TQueryC(TContractsPackageQuery(TDoNotViolateInLineLinkageConstraintsQuery()))
46+
}
47+
48+
Query checkMathLibraryFunctionParametersQuery() {
49+
//autogenerate `Query` type
50+
result =
51+
// `Query` type for `checkMathLibraryFunctionParameters` query
52+
TQueryC(TContractsPackageQuery(TCheckMathLibraryFunctionParametersQuery()))
53+
}
54+
55+
Query functionErrorInformationUntestedQuery() {
56+
//autogenerate `Query` type
57+
result =
58+
// `Query` type for `functionErrorInformationUntested` query
59+
TQueryC(TContractsPackageQuery(TFunctionErrorInformationUntestedQuery()))
60+
}
61+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Concurrency2
99
import Concurrency3
1010
import Concurrency4
1111
import Concurrency5
12+
import Contracts
1213
import Contracts1
1314
import Contracts2
1415
import Contracts3
@@ -80,6 +81,7 @@ newtype TCQuery =
8081
TConcurrency3PackageQuery(Concurrency3Query q) or
8182
TConcurrency4PackageQuery(Concurrency4Query q) or
8283
TConcurrency5PackageQuery(Concurrency5Query q) or
84+
TContractsPackageQuery(ContractsQuery q) or
8385
TContracts1PackageQuery(Contracts1Query q) or
8486
TContracts2PackageQuery(Contracts2Query q) or
8587
TContracts3PackageQuery(Contracts3Query q) or
@@ -151,6 +153,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
151153
isConcurrency3QueryMetadata(query, queryId, ruleId, category) or
152154
isConcurrency4QueryMetadata(query, queryId, ruleId, category) or
153155
isConcurrency5QueryMetadata(query, queryId, ruleId, category) or
156+
isContractsQueryMetadata(query, queryId, ruleId, category) or
154157
isContracts1QueryMetadata(query, queryId, ruleId, category) or
155158
isContracts2QueryMetadata(query, queryId, ruleId, category) or
156159
isContracts3QueryMetadata(query, queryId, ruleId, category) or

rule_packages/c/Contracts.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"CERT-C": {
3+
"MSC40-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "Inlined external functions are prohibited by the language standard from defining modifiable static or thread storage objects, or referencing identifiers with internal linkage.",
10+
"kind": "problem",
11+
"name": "Do not violate inline linkage constraints",
12+
"precision": "very-high",
13+
"severity": "error",
14+
"short_name": "DoNotViolateInLineLinkageConstraints",
15+
"tags": [
16+
"correctness"
17+
]
18+
}
19+
],
20+
"title": "Do not violate constraints"
21+
}
22+
},
23+
"MISRA-C-2012": {
24+
"DIR-4-11": {
25+
"properties": {
26+
"obligation": "required"
27+
},
28+
"queries": [
29+
{
30+
"description": "Range, domain or pole errors in math functions may return unexpected values, trigger floating-point exceptions or set unexpected error modes.",
31+
"kind": "problem",
32+
"name": "The validity of values passed to `math.h` library functions shall be checked",
33+
"precision": "high",
34+
"severity": "error",
35+
"short_name": "CheckMathLibraryFunctionParameters",
36+
"shared_implementation_short_name": "UncheckedRangeDomainPoleErrors",
37+
"tags": [
38+
"correctness"
39+
]
40+
}
41+
],
42+
"title": "The validity of values passed to library functions shall be checked"
43+
},
44+
"DIR-4-7": {
45+
"properties": {
46+
"obligation": "required"
47+
},
48+
"queries": [
49+
{
50+
"description": "A function (whether it is part of the standard library, a third party library or a user defined function) may provide some means of indicating the occurrence of an error. This may be via a global error flag, a parametric error flag, a special return value or some other means. Whenever such a mechanism is provided by a function the calling program shall check for the indication of an error as soon as the function returns.",
51+
"kind": "problem",
52+
"name": "If a function generates error information, then that error information shall be tested",
53+
"precision": "very-high",
54+
"severity": "recommendation",
55+
"short_name": "FunctionErrorInformationUntested",
56+
"shared_implementation_short_name": "FunctionErroneousReturnValueNotTested",
57+
"tags": [
58+
"maintainability"
59+
]
60+
}
61+
],
62+
"title": "If a function returns error information, then that error information shall be tested"
63+
}
64+
}
65+
}

rule_packages/cpp/Expressions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"precision": "very-high",
8787
"severity": "recommendation",
8888
"short_name": "FunctionErroneousReturnValueNotTested",
89+
"shared_implementation_short_name": "FunctionErroneousReturnValueNotTested",
8990
"tags": [
9091
"maintainability"
9192
]

0 commit comments

Comments
 (0)