Skip to content

Commit 0c7b503

Browse files
save work
1 parent ce5b364 commit 0c7b503

File tree

19 files changed

+298
-66
lines changed

19 files changed

+298
-66
lines changed

amendments.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ c,MISRA-C-2012,Corrigendum2,RULE-1-4,Yes,Replace,No,Easy
2828
c,MISRA-C-2012,Corrigendum2,RULE-9-1,Yes,Refine,No,Easy
2929
c,MISRA-C-2012,Corrigendum2,RULE-9-2,Yes,Refine,No,Import
3030
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,No,Import
31-
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,No,Easy
31+
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
3232
c,MISRA-C-2012,Corrigendum2,RULE-8-2,Yes,Clarification,No,Import
33-
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,No,Easy
33+
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,Yes,Easy
3434
c,MISRA-C-2012,Corrigendum2,RULE-8-7,Yes,Clarification,No,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,No,Import
3737
c,MISRA-C-2012,Corrigendum2,RULE-11-3,Yes,Clarification,No,Import
3838
c,MISRA-C-2012,Corrigendum2,RULE-11-6,Yes,Clarification,No,Import
3939
c,MISRA-C-2012,Corrigendum2,RULE-13-2,Yes,Clarification,No,Import
4040
c,MISRA-C-2012,Corrigendum2,RULE-13-6,Yes,Clarification,No,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,No,Import
4343
c,MISRA-C-2012,Corrigendum2,RULE-17-4,Yes,Clarification,No,Import
4444
c,MISRA-C-2012,Corrigendum2,RULE-17-5,Yes,Clarification,No,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,No,Import
4747
c,MISRA-C-2012,Corrigendum2,RULE-21-19,Yes,Clarification,No,Import
48-
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,No,Easy
48+
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,Yes,Easy
4949
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,No,Import

c/misra/src/codingstandards/c/misra/EssentialTypes.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,15 @@ class EssentialBinaryArithmeticExpr extends EssentialExpr, BinaryArithmeticOpera
297297
exists(
298298
Type leftEssentialType, Type rightEssentialType,
299299
EssentialTypeCategory leftEssentialTypeCategory,
300-
EssentialTypeCategory rightEssentialTypeCategory
300+
EssentialTypeCategory rightEssentialTypeCategory,
301+
int intTypeSize
301302
|
302303
leftEssentialType = getEssentialType(getLeftOperand()) and
303304
rightEssentialType = getEssentialType(getRightOperand()) and
304305
leftEssentialTypeCategory = getEssentialTypeCategory(leftEssentialType) and
305-
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType)
306+
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType) and
307+
// For rules around addition/subtraction with char types:
308+
intTypeSize = any(IntType i | i.isSigned()).getSize()
306309
|
307310
if
308311
leftEssentialTypeCategory = EssentiallySignedType() and
@@ -338,15 +341,18 @@ class EssentialBinaryArithmeticExpr extends EssentialExpr, BinaryArithmeticOpera
338341
(
339342
leftEssentialTypeCategory =
340343
[EssentiallySignedType(), EssentiallyUnsignedType().(TEssentialTypeCategory)]
344+
and leftEssentialType.getSize() <= intTypeSize
341345
or
342346
rightEssentialTypeCategory =
343347
[EssentiallySignedType(), EssentiallyUnsignedType().(TEssentialTypeCategory)]
348+
and rightEssentialType.getSize() <= intTypeSize
344349
)
345350
or
346351
this instanceof SubExpr and
347352
leftEssentialTypeCategory = EssentiallyCharacterType() and
348353
rightEssentialTypeCategory =
349354
[EssentiallySignedType(), EssentiallyUnsignedType().(TEssentialTypeCategory)]
355+
and rightEssentialType.getSize() <= intTypeSize
350356
then result instanceof PlainCharType
351357
else result = this.getStandardType()
352358
)

c/misra/src/rules/RULE-10-2/AdditionSubtractionOnEssentiallyCharType.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
// But the overall essential type is not essentially character type
3333
getEssentialTypeCategory(getEssentialType(addOrSub)) = EssentiallyCharacterType()
3434
or
35-
// Or this is a subtration of one character with another, which is permitted, but produces an integral type
35+
// Or this is a subtraction of one character with another, which is permitted, but produces an integral type
3636
getEssentialTypeCategory(getEssentialType(addOrSub.getLeftOperand())) =
3737
EssentiallyCharacterType() and
3838
getEssentialTypeCategory(getEssentialType(addOrSub.getRightOperand())) =
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
| test.c:15:3:15:11 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
2-
| test.c:16:3:16:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
3-
| test.c:17:3:17:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
4-
| test.c:18:3:18:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
5-
| test.c:19:3:19:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
6-
| test.c:20:3:20:10 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
7-
| test.c:21:3:21:10 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
8-
| test.c:27:3:27:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
9-
| test.c:28:3:28:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
10-
| test.c:29:3:29:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
11-
| test.c:30:3:30:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
12-
| test.c:31:3:31:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
13-
| test.c:32:3:32:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
14-
| test.c:33:3:33:10 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
15-
| test.c:34:3:34:10 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
1+
| test.c:19:3:19:11 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
2+
| test.c:20:3:20:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
3+
| test.c:21:3:21:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
4+
| test.c:22:3:22:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
5+
| test.c:23:3:23:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
6+
| test.c:24:3:24:10 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
7+
| test.c:25:3:25:10 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
8+
| test.c:28:3:28:9 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
9+
| test.c:29:3:29:10 | ... + ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
10+
| test.c:35:3:35:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
11+
| test.c:36:3:36:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
12+
| test.c:37:3:37:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
13+
| test.c:38:3:38:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
14+
| test.c:39:3:39:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
15+
| test.c:40:3:40:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
16+
| test.c:41:3:41:10 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
17+
| test.c:42:3:42:10 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
18+
| test.c:45:3:45:9 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |
19+
| test.c:46:3:46:10 | ... - ... | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations |

c/misra/test/rules/RULE-10-2/test.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ void testRules() {
55
enum E1 { A, B, C } e1 = A;
66
signed int i = 100;
77
unsigned int u = 100;
8+
signed short s = 100;
9+
unsigned short us = 100;
10+
signed long l = 100L;
11+
unsigned long ul = 100UL;
812
float f = 10.0f;
913

1014
// Addition cases
@@ -19,8 +23,12 @@ void testRules() {
1923
b + 'a'; // NON_COMPLIANT
2024
'a' + e1; // NON_COMPLIANT
2125
e1 + 'a'; // NON_COMPLIANT
26+
'a' + s; // COMPLIANT
27+
'a' + us; // COMPLIANT
28+
'a' + l; // NON_COMPLIANT
29+
'a' + ul; // NON_COMPLIANT
2230

23-
// Subtration cases
31+
// Subtraction cases
2432
'a' - i; // COMPLIANT
2533
'a' - u; // COMPLIANT
2634
'a' - 'a'; // COMPLIANT
@@ -32,4 +40,8 @@ void testRules() {
3240
'a' - b; // NON_COMPLIANT
3341
e1 - 'a'; // NON_COMPLIANT
3442
'a' - e1; // NON_COMPLIANT
43+
'a' - s; // COMPLIANT
44+
'a' - us; // COMPLIANT
45+
'a' - l; // NON_COMPLIANT
46+
'a' - ul; // NON_COMPLIANT
3547
}

c/misra/test/rules/RULE-14-3/ControllingExprInvariant.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| test.c:27:10:27:14 | ... < ... | Controlling expression in loop statement has an invariant value. |
66
| test.c:37:3:37:6 | 1 | Controlling expression in conditional statement has an invariant value. |
77
| test.c:38:3:38:3 | 1 | Controlling expression in conditional statement has an invariant value. |
8+
| test.c:45:10:45:26 | ... && ... | Controlling expression in loop statement has an invariant value. |

c/misra/test/rules/RULE-14-3/test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ void f5(bool b1) {
3737
true ? 1 : 2; // NON_COMPLIANT
3838
1 ? 1 : 2; // NON_COMPLIANT
3939
b1 ? 1 : 2; // COMPLIANT
40+
}
41+
42+
void f6(int p1) {
43+
while (p1 < 10 && p1 > 12) { // NON_COMPLIANT[FALSE_NEGATIVE]
44+
}
45+
while (1 == 0 && p1 > 12) { // NON_COMPLIANT
46+
}
4047
}

c/misra/test/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
| test.c:58:5:58:22 | return ... | wchar_t * function w_sample3 is returning a string literal. |
77
| test.c:69:3:69:9 | call to sample4 | char * parameter of sample4 is passed a string literal. |
88
| test.c:78:3:78:11 | call to w_sample4 | wchar_t * parameter of w_sample4 is passed a string literal. |
9+
| test.c:91:3:91:11 | call to w_sample7 | char * parameter of w_sample7 is passed a string literal. |

c/misra/test/rules/RULE-7-4/test.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,16 @@ void w_call45() {
7979
w_sample5(L"string9"); // COMPLIANT: passing string literal to const char*
8080
}
8181

82+
void w_sample6(int x, ...) {}
83+
84+
void w_call6() {
85+
w_sample6(1, "string10"); // COMPLIANT by first (and only) exception
86+
}
87+
88+
void w_sample7(char* x, ...) {}
89+
90+
void w_call7() {
91+
w_sample7("string11", 1); // NON_COMPLIANT, does not fit exceptional case
92+
}
93+
8294
int main() { return 0; }

c/misra/test/rules/RULE-8-3/function1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ a f21(wi w, wi h) { // NON_COMPLIANT
2424

2525
void f22(int f22b, int f22a) { // NON_COMPLIANT
2626
return;
27+
}
28+
29+
void f23(int f23a) { // COMPLIANT
30+
return;
2731
}

c/misra/test/rules/RULE-8-3/function2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ typedef long a;
1616

1717
extern a f21(wi w, hi h); // NON_COMPLIANT
1818

19-
extern void f22(int f22a, int f22b); // NON_COMPLIANT
19+
extern void f22(int f22a, int f22b); // NON_COMPLIANT
20+
21+
extern void f23(int); // COMPLIANT
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- `RULE-8-3` - `DeclarationsOfAFunctionSameNameAndType.ql`:
2+
- Implement new exception, unnamed parameters are not covered by this rule.
3+
- `RULE-10-2` - `AdditionSubtractionOnEssentiallCharType.ql`:
4+
- Disallow `+` and `-` operations with an essentially char type and other types larger than int type.
5+
- Note, this change affects the essential type of such expressions, which may affect other essential types rules.
6+
- `RULE-18-1`, `M5-0-16` - `PointerAndDerivedPointerMustAddressSameArray.ql`, `PointerAndDerivedPointerAccessDifferentArray.ql`:
7+
- Treat casts to byte pointers as pointers to arrays of the size of the pointed-to type
8+
- Fix typo in report message, "passed" replaced with "past."
9+
- `RULE-21-10`, `RULE-25-5-3`, `ENV34-C` - `CallToSetlocaleInvalidatesOldPointers.ql`, `CallToSetlocaleInvalidatesOldPointersMisra.ql`, `DoNotStorePointersReturnedByEnvFunctions.ql`:
10+
- Report usage of returned pointers from `asctime`, `ctime`, during a call to either of the former.
11+
- Report usage of returned pointers from `gmtime`, `localtime`, during a call to either of the former.

cpp/common/src/codingstandards/cpp/Compatible.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ predicate parameterTypesIncompatible(FunctionDeclarationEntry f1, FunctionDeclar
2121

2222
predicate parameterNamesIncompatible(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
2323
f1.getDeclaration() = f2.getDeclaration() and
24-
exists(ParameterDeclarationEntry p1, ParameterDeclarationEntry p2, int i |
25-
p1 = f1.getParameterDeclarationEntry(i) and
26-
p2 = f2.getParameterDeclarationEntry(i)
24+
exists(string p1Name, string p2Name, int i |
25+
p1Name = f1.getParameterDeclarationEntry(i).getName() and
26+
p2Name = f2.getParameterDeclarationEntry(i).getName()
2727
|
28-
not p1.getName() = p2.getName()
28+
not p1Name = p2Name
2929
)
3030
}

0 commit comments

Comments
 (0)