Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a03892c

Browse filesBrowse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/final-misra-c-rule-amendments
2 parents 6b9dc41 + d34b85c commit a03892c
Copy full SHA for a03892c

File tree

207 files changed

+7887
-666
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

207 files changed

+7887
-666
lines changed

‎.github/workflows/upgrade_codeql_dependencies.yml

Copy file name to clipboardExpand all lines: .github/workflows/upgrade_codeql_dependencies.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
5454
5555
- name: Create Pull Request
56-
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
56+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
5757
with:
5858
title: "Upgrade `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}"
5959
body: |

‎amendments.csv

Copy file name to clipboardExpand all lines: amendments.csv
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,Yes,Import
1111
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,Yes,Import
1212
c,MISRA-C-2012,Amendment3,RULE-21-11,Yes,Clarification,Yes,Import
1313
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,Yes,Easy
14-
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,No,Easy
15-
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,No,Easy
16-
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,No,Very Hard
14+
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,Yes,Easy
15+
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,Yes,Easy
16+
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,Yes,Very Hard
1717
c,MISRA-C-2012,Amendment4,RULE-18-6,Yes,Expand,Yes,Medium
1818
c,MISRA-C-2012,Amendment4,RULE-18-8,Yes,Split,Yes,Easy
1919
c,MISRA-C-2012,Amendment4,RULE-2-2,Yes,Clarification,Yes,Import
2020
c,MISRA-C-2012,Amendment4,RULE-2-7,Yes,Clarification,Yes,Import
21-
c,MISRA-C-2012,Amendment4,RULE-3-1,Yes,Refine,No,Easy
21+
c,MISRA-C-2012,Amendment4,RULE-3-1,Yes,Refine,Yes,Easy
2222
c,MISRA-C-2012,Amendment4,RULE-8-6,Yes,Clarification,Yes,Import
2323
c,MISRA-C-2012,Amendment4,RULE-8-9,Yes,Clarification,Yes,Import
2424
c,MISRA-C-2012,Amendment4,RULE-9-4,Yes,Clarification,Yes,Import
2525
c,MISRA-C-2012,Amendment4,RULE-10-1,Yes,Clarification,Yes,Import
2626
c,MISRA-C-2012,Amendment4,RULE-18-3,Yes,Clarification,Yes,Import
2727
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,No,Easy
28-
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,No,Easy
28+
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,Yes,Easy
2929
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,Yes,Import
30-
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,No,Easy
30+
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
3131
c,MISRA-C-2012,Corrigendum2,RULE-8-2,Yes,Clarification,Yes,Import
32-
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,No,Easy
32+
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,Yes,Easy
3333
c,MISRA-C-2012,Corrigendum2,RULE-8-7,Yes,Clarification,Yes,Import
3434
c,MISRA-C-2012,Corrigendum2,RULE-10-1,Yes,Clarification,Yes,Import
35-
c,MISRA-C-2012,Corrigendum2,RULE-10-2,Yes,Refine,No,Easy
35+
c,MISRA-C-2012,Corrigendum2,RULE-10-2,Yes,Refine,Yes,Easy
3636
c,MISRA-C-2012,Corrigendum2,RULE-10-3,Yes,Clarification,Yes,Import
3737
c,MISRA-C-2012,Corrigendum2,RULE-11-3,Yes,Clarification,Yes,Import
3838
c,MISRA-C-2012,Corrigendum2,RULE-11-6,Yes,Clarification,Yes,Import
3939
c,MISRA-C-2012,Corrigendum2,RULE-13-2,Yes,Clarification,Yes,Import
4040
c,MISRA-C-2012,Corrigendum2,RULE-13-6,Yes,Clarification,Yes,Import
41-
c,MISRA-C-2012,Corrigendum2,RULE-14-3,Yes,Refine,No,Easy
41+
c,MISRA-C-2012,Corrigendum2,RULE-14-3,Yes,Refine,Yes,Easy
4242
c,MISRA-C-2012,Corrigendum2,RULE-15-7,Yes,Clarification,Yes,Import
4343
c,MISRA-C-2012,Corrigendum2,RULE-17-4,Yes,Clarification,Yes,Import
4444
c,MISRA-C-2012,Corrigendum2,RULE-17-5,Yes,Clarification,Yes,Import
45-
c,MISRA-C-2012,Corrigendum2,RULE-18-1,Yes,Refine,No,Easy
45+
c,MISRA-C-2012,Corrigendum2,RULE-18-1,Yes,Refine,Yes,Easy
4646
c,MISRA-C-2012,Corrigendum2,RULE-20-14,No,Clarification,Yes,Import
4747
c,MISRA-C-2012,Corrigendum2,RULE-21-19,Yes,Clarification,Yes,Import
48-
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,No,Easy
49-
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,Yes,Import
48+
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,Yes,Easy
49+
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,Yes,Import

‎c/cert/src/qlpack.yml

Copy file name to clipboardExpand all lines: c/cert/src/qlpack.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

‎c/cert/src/rules/ARR39-C/DoNotAddOrSubtractAScaledIntegerToAPointer.ql

Copy file name to clipboardExpand all lines: c/cert/src/rules/ARR39-C/DoNotAddOrSubtractAScaledIntegerToAPointer.ql
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import cpp
1515
import codingstandards.c.cert
16-
import codingstandards.cpp.Pointers
16+
import codingstandards.cpp.types.Pointers
1717
import semmle.code.cpp.dataflow.TaintTracking
1818
import ScaledIntegerPointerArithmeticFlow::PathGraph
1919

‎c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql

Copy file name to clipboardExpand all lines: c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import cpp
1818
import codingstandards.c.cert
19-
import codingstandards.cpp.Compatible
19+
import codingstandards.cpp.types.Compatible
2020
import ExternalIdentifiers
2121

2222
from ExternalIdentifiers d, FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
@@ -29,12 +29,10 @@ where
2929
f1.getName() = f2.getName() and
3030
(
3131
//return type check
32-
not typesCompatible(f1.getType(), f2.getType())
32+
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig>::equalReturnTypes(f1, f2)
3333
or
3434
//parameter type check
35-
parameterTypesIncompatible(f1, f2)
36-
or
37-
not f1.getNumberOfParameters() = f2.getNumberOfParameters()
35+
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig>::equalParameterTypes(f1, f2)
3836
) and
3937
// Apply ordering on start line, trying to avoid the optimiser applying this join too early
4038
// in the pipeline

‎c/cert/test/qlpack.yml

Copy file name to clipboardExpand all lines: c/cert/test/qlpack.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:
+150Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import cpp
2+
import codingstandards.cpp.Macro
3+
import codingstandards.cpp.MatchingParenthesis
4+
5+
string genericRegexp() { result = "\\b_Generic\\s*\\(\\s*(.+),.*" }
6+
7+
bindingset[input]
8+
string deparenthesize(string input) {
9+
input = "(" + result + ")" and
10+
result = input.substring(1, input.length() - 1)
11+
}
12+
13+
class GenericMacro extends Macro {
14+
string ctrlExpr;
15+
16+
GenericMacro() { ctrlExpr = getBody().regexpCapture(genericRegexp(), 1).trim() }
17+
18+
string getAParameter() { result = this.(FunctionLikeMacro).getAParameter() }
19+
20+
string getControllingExprString() {
21+
if exists(string s | s = deparenthesize(ctrlExpr))
22+
then result = deparenthesize(ctrlExpr).trim()
23+
else result = ctrlExpr
24+
}
25+
26+
/**
27+
* Whether the controlling expression of the `_Generic` expr in this macro's controlling
28+
* expression refers to one of this macro's parameters.
29+
*/
30+
predicate hasControllingExprFromMacroParameter() {
31+
getControllingExprString().matches(getAParameter())
32+
}
33+
}
34+
35+
class GenericMacroString extends string {
36+
GenericMacroString() { this = any(Macro m).getBody() and this.matches("%_Generic%") }
37+
}
38+
39+
import MatchingParenthesis<GenericMacroString>
40+
41+
class ParsedGenericMacro extends Macro {
42+
ParsedRoot macroBody;
43+
Parsed genericBody;
44+
string beforeGenericBody;
45+
string afterGenericBody;
46+
47+
ParsedGenericMacro() {
48+
macroBody.getInputString() = this.getBody() and
49+
exists(ParsedText genericText |
50+
genericText.getText().matches("%_Generic%") and
51+
genericBody = genericText.getParent().getChild(genericText.getChildIdx() + 1) and
52+
genericBody.getRoot() = macroBody
53+
) and
54+
beforeGenericBody =
55+
textFrom(macroBody.getStartToken(), genericBody.getStartToken().getPrevious()) and
56+
(
57+
if exists(genericBody.getEndToken().getNext())
58+
then afterGenericBody = textFrom(genericBody.getEndToken().getNext(), macroBody.getEndToken())
59+
else afterGenericBody = ""
60+
)
61+
}
62+
63+
string getAParameter() { result = this.(FunctionLikeMacro).getAParameter() }
64+
65+
int getAParsedGenericCommaSeparatorOffset() {
66+
exists(ParsedText text |
67+
text.getParent() = genericBody and
68+
result = text.getStartToken().getStartPos() + text.getText().indexOf(",")
69+
)
70+
}
71+
72+
int getAParsedGenericColonSeparatorOffset() {
73+
exists(ParsedText text |
74+
text.getParent() = genericBody and
75+
result = text.getStartToken().getStartPos() + text.getText().indexOf(":")
76+
)
77+
}
78+
79+
int getParsedGenericCommaSeparatorOffset(int i) {
80+
result = rank[i](int index | index = getAParsedGenericCommaSeparatorOffset())
81+
}
82+
83+
bindingset[start, end]
84+
int getParsedGenericColon(int start, int end) {
85+
result =
86+
min(int offset |
87+
offset = getAParsedGenericColonSeparatorOffset() and
88+
offset >= start and
89+
offset <= end
90+
)
91+
}
92+
93+
predicate hasParsedFullSelectionRange(int idx, int start, int end) {
94+
idx = 1 and
95+
start = genericBody.getStartToken().getEndPos() and
96+
end = getParsedGenericCommaSeparatorOffset(idx)
97+
or
98+
not exists(getParsedGenericCommaSeparatorOffset(idx)) and
99+
start = getParsedGenericCommaSeparatorOffset(idx - 1) and
100+
end = genericBody.getEndToken().getStartPos()
101+
or
102+
start = getParsedGenericCommaSeparatorOffset(idx - 1) and
103+
end = getParsedGenericCommaSeparatorOffset(idx)
104+
}
105+
106+
string getSelectionString(int idx) {
107+
exists(int start, int rawStart, int end |
108+
hasParsedFullSelectionRange(idx, rawStart, end) and
109+
(
110+
if exists(getParsedGenericColon(rawStart, end))
111+
then start = getParsedGenericColon(rawStart, end)
112+
else start = rawStart
113+
) and
114+
result = genericBody.getInputString().substring(start, end)
115+
)
116+
}
117+
118+
string getControllingExprString() { result = getSelectionString(1).trim() }
119+
120+
bindingset[str, word]
121+
private int countWordInString(string word, string str) {
122+
result =
123+
max(int occurrence |
124+
exists(str.regexpFind("\\b" + word + "\\b", occurrence, _)) or occurrence = -1
125+
|
126+
occurrence + 1
127+
)
128+
}
129+
130+
int expansionsOutsideExpr(string parameter) {
131+
parameter = getAParameter() and
132+
result =
133+
countWordInString(parameter, beforeGenericBody) +
134+
countWordInString(parameter, afterGenericBody)
135+
}
136+
137+
int expansionsInsideSelection(string parameter, int idx) {
138+
parameter = getAParameter() and
139+
result = countWordInString(parameter, getSelectionString(idx))
140+
}
141+
142+
int expansionsInsideControllingExpr(string parameter) {
143+
result = expansionsInsideSelection(parameter, 1)
144+
}
145+
146+
int expansionsInsideAssociation(string parameter, int idx) {
147+
not idx = 0 and
148+
result = expansionsInsideSelection(parameter, idx + 1)
149+
}
150+
}

‎c/common/src/codingstandards/c/OutOfBounds.qll

Copy file name to clipboardExpand all lines: c/common/src/codingstandards/c/OutOfBounds.qll
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import cpp
8-
import codingstandards.cpp.Pointers
8+
import codingstandards.cpp.types.Pointers
99
import codingstandards.c.Variable
1010
import codingstandards.cpp.Allocations
1111
import codingstandards.cpp.Overflow

‎c/common/src/codingstandards/c/UndefinedBehavior.qll

Copy file name to clipboardExpand all lines: c/common/src/codingstandards/c/UndefinedBehavior.qll
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cpp
2-
import codingstandards.cpp.Pointers
2+
import codingstandards.cpp.types.Pointers
33
import codingstandards.cpp.UndefinedBehavior
44

55
/**

‎c/common/src/qlpack.yml

Copy file name to clipboardExpand all lines: c/common/src/qlpack.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

‎c/common/test/qlpack.yml

Copy file name to clipboardExpand all lines: c/common/test/qlpack.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards-tests
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| test.c:4:13:4:18 | ... + ... | Array pointer p2 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
2-
| test.c:5:13:5:18 | ... + ... | Array pointer p3 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
3-
| test.c:6:13:6:18 | & ... | Array pointer p4 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
4-
| test.c:11:8:11:11 | ... -- | Array pointer p7 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
5-
| test.c:12:8:12:9 | p3 | Array pointer p8 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
1+
| test.c:4:13:4:18 | ... + ... | Array pointer p2 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
2+
| test.c:5:13:5:18 | ... + ... | Array pointer p3 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
3+
| test.c:6:13:6:18 | & ... | Array pointer p4 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
4+
| test.c:11:8:11:11 | ... -- | Array pointer p7 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
5+
| test.c:12:8:12:9 | p3 | Array pointer p8 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |

‎c/common/test/rules/readofuninitializedmemory/test.c

Copy file name to clipboardExpand all lines: c/common/test/rules/readofuninitializedmemory/test.c
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,6 @@ void test_non_default_init() {
9494
static struct A ss;
9595
use_struct_A(
9696
ss); // COMPLIANT - static struct type variables are zero initialized
97+
_Atomic int x;
98+
use_int(x); // COMPLIANT - atomics are special, covered by other rules
9799
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.