Skip to content

Commit cced8d4

Browse files
authored
Tests for Contracts6
* tests for contracts6
1 parent f9a2c5e commit cced8d4

File tree

6 files changed

+193
-4
lines changed

6 files changed

+193
-4
lines changed

.vscode/tasks.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
"Classes",
193193
"Comments",
194194
"Contracts1",
195+
"Contracts2",
196+
"Contracts3",
197+
"Contracts4",
198+
"Contracts5",
199+
"Contracts6",
195200
"Concurrency",
196201
"Concurrency",
197202
"Concurrency1",

c/cert/test/rules/EXP40-C/test.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
void f1() {
2+
const int a = 3;
3+
int *aa;
4+
5+
aa = &a; // NON_COMPLIANT
6+
*aa = 100;
7+
}
8+
9+
void f1a() {
10+
const int a = 3;
11+
int *aa;
12+
13+
aa = &a; // COMPLIANT
14+
}
15+
16+
void f2() {
17+
int a = 3;
18+
int *aa;
19+
a = 3;
20+
21+
aa = &a;
22+
*aa = a;
23+
*aa = &a;
24+
}
25+
26+
void f4a(int *a) {
27+
*a = 100; // NON_COMPLAINT
28+
}
29+
30+
void f4b(int *a) {}
31+
32+
void f4() {
33+
const int a = 100;
34+
int *p1 = &a; // NON_COMPLIANT
35+
const int **p2;
36+
37+
*p2 = &a; // NON_COMPLIANT
38+
39+
f4a(p1); // NON_COMPLIANT
40+
f4a(*p2); // NON_COMPLIANT
41+
}
42+
43+
void f5() {
44+
const int a = 100;
45+
int *p1 = &a; // COMPLIANT
46+
const int **p2;
47+
48+
*p2 = &a; // COMPLIANT
49+
50+
f4b(p1);
51+
f4b(*p2);
52+
}

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
3+
const short int s1 = 15;
4+
const short int s2 = -1;
5+
const short int s3 = 16;
6+
const int s4 = -1;
7+
const int s5 = 32;
8+
const int s6 = 21;
9+
10+
const long int s7 = 64;
11+
const long int s8 = 63;
12+
13+
void f1() {
14+
int a;
15+
short b;
16+
long c;
17+
char d;
18+
19+
a = a << s1; // COMPLIANT
20+
a = a << s2; // NON_COMPLIANT
21+
a = a << s3; // COMPLIANT
22+
a = a << s4; // NON_COMPLIANT
23+
a = a << s5; // NON_COMPLIANT
24+
a = a << s6; // COMPLIANT
25+
a = a << s7; // NON_COMPLIANT
26+
a = a << s8; // NON_COMPLIANT
27+
28+
b = b << s1; // COMPLIANT
29+
b = b << s2; // NON_COMPLIANT
30+
b = b << s3; // NON_COMPLIANT
31+
b = b << s4; // NON_COMPLIANT
32+
b = b << s5; // NON_COMPLIANT
33+
b = b << s6; // NON_COMPLIANT
34+
b = b << s7; // NON_COMPLIANT
35+
b = b << s8; // NON_COMPLIANT
36+
37+
c = c << s1; // COMPLIANT
38+
c = c << s2; // NON_COMPLIANT
39+
c = c << s3; // COMPLIANT
40+
c = c << s4; // NON_COMPLIANT
41+
c = c << s5; // COMPLIANT
42+
c = c << s6; // COMPLIANT
43+
c = c << s7; // NON_COMPLIANT
44+
c = c << s8; // COMPLIANT
45+
46+
d = d << -1; // NON_COMPLIANT
47+
d = d << 8; // NON_COMPLIANT
48+
d = d << 7; // COMPLIANT
49+
d = d << 0; // COMPLIANT
50+
}
51+
52+
void f2() {
53+
int a;
54+
short b;
55+
char c;
56+
long long d;
57+
58+
int aa = 10;
59+
aa++;
60+
61+
a = a << aa;
62+
b = b << aa;
63+
c = c << aa;
64+
d = d << aa;
65+
}

c/misra/test/rules/RULE-17-5/test.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
void f1(int ar[3]);
2+
void f2(int a, int ar[3]);
3+
void f3(int *ar);
4+
void f4(int a, int *ar);
5+
6+
void t1() {
7+
int *ar;
8+
9+
int ar2[3] = {1, 2};
10+
int *ar2p = ar2;
11+
12+
int ar3[3] = {1, 2, 3};
13+
int *ar3p = ar3;
14+
15+
int ar4[4] = {1, 2, 3};
16+
int *ar4p = ar4;
17+
18+
f1(0); // NON_COMPLAINT
19+
f1(ar); // NON_COMPLAINT
20+
f1(ar2); // NON_COMPLIANT
21+
f1(ar2p); // NON_COMPLIANT
22+
f1(ar3); // COMPLIANT
23+
f1(ar3p); // COMPLIANT
24+
f1(ar4); // COMPLIANT
25+
26+
f2(0, 0); // NON_COMPLAINT
27+
f2(0, ar); // NON_COMPLAINT
28+
f2(0, ar2); // NON_COMPLIANT
29+
f2(0, ar2p); // NON_COMPLIANT
30+
f2(0, ar3); // COMPLIANT
31+
f2(0, ar3p); // COMPLIANT
32+
f2(0, ar4); // COMPLIANT
33+
34+
f3(0); // COMPLAINT
35+
f3(ar); // COMPLAINT
36+
f3(ar2); // COMPLIANT
37+
f3(ar2p); // COMPLIANT
38+
f3(ar3); // COMPLIANT
39+
f3(ar3p); // COMPLIANT
40+
f3(ar4); // COMPLIANT
41+
42+
f4(0, 0); // COMPLAINT
43+
f4(0, ar); // COMPLAINT
44+
f4(0, ar2); // COMPLIANT
45+
f4(0, ar2p); // COMPLIANT
46+
f4(0, ar3); // COMPLIANT
47+
f4(0, ar3p); // COMPLIANT
48+
f4(0, ar4); // COMPLIANT
49+
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
void f1() {}
2+
int f2() { return 0; }
3+
4+
int t1() {
5+
f1();
6+
f2(); // NON_COMPLAINT
7+
(void)f2(); // COMPLIANT
8+
int a = f2(); // COMPLIANT
9+
a = f2(); // COMPLIANT
10+
11+
void (*fp1)(void) = &f1;
12+
int (*fp2)(void) = &f2;
13+
14+
(*f1)(); // COMPLIANT
15+
(*f2)(); // NON_COMPLIANT
16+
(void)(*f2)(); // COMPLIANT
17+
a = (*f2)(); // COMPLIANT
18+
}

rules.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ c,CERT-C,EXP35-C,Yes,Rule,,,Do not modify objects with temporary lifetime,,Inval
523523
c,CERT-C,EXP36-C,Yes,Rule,,,Do not cast pointers into more strictly aligned pointer types,,Pointers3,Medium,
524524
c,CERT-C,EXP37-C,Yes,Rule,,,Call functions with the correct number and type of arguments,,Expressions,Easy,
525525
c,CERT-C,EXP39-C,Yes,Rule,,,Do not access a variable through a pointer of an incompatible type,,Pointers3,Medium,
526-
c,CERT-C,EXP40-C,Yes,Rule,,,Do not modify constant objects,,Contracts,Medium,
526+
c,CERT-C,EXP40-C,Yes,Rule,,,Do not modify constant objects,,Contracts6,Medium,
527527
c,CERT-C,EXP42-C,Yes,Rule,,,Do not compare padding data,,Memory,Medium,
528528
c,CERT-C,EXP43-C,Yes,Rule,,,Avoid undefined behavior when using restrict-qualified pointers,,Pointers3,Medium,
529529
c,CERT-C,EXP44-C,Yes,Rule,,,"Do not rely on side effects in operands to sizeof, _Alignof, or _Generic",M5-3-4,SideEffects1,Medium,
@@ -683,7 +683,7 @@ c,MISRA-C-2012,RULE-11-7,Yes,Required,,,A cast shall not be performed between po
683683
c,MISRA-C-2012,RULE-11-8,Yes,Required,,,A cast shall not remove any const or volatile qualification from the type pointed to by a pointer,,Pointers1,Easy,
684684
c,MISRA-C-2012,RULE-11-9,Yes,Required,,,The macro NULL shall be the only permitted form of integer null pointer constant,,Pointers1,Easy,
685685
c,MISRA-C-2012,RULE-12-1,Yes,Advisory,,,The precedence of operators within expressions should be made explicit,,SideEffects1,Medium,
686-
c,MISRA-C-2012,RULE-12-2,Yes,Required,,,The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand,,Contracts,Hard,
686+
c,MISRA-C-2012,RULE-12-2,Yes,Required,,,The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand,,Contracts6,Hard,
687687
c,MISRA-C-2012,RULE-12-3,Yes,Advisory,,,The comma operator should not be used,M5-18-1,Banned,Import,
688688
c,MISRA-C-2012,RULE-12-4,Yes,Advisory,,,Evaluation of constant expressions should not lead to unsigned integer wrap-around,INT30-C,Types,Easy,
689689
c,MISRA-C-2012,RULE-12-5,Yes,Mandatory,,,The sizeof operator shall not have an operand which is a function parameter declared as �array of type�,,Types,Medium,
@@ -715,9 +715,9 @@ c,MISRA-C-2012,RULE-17-1,Yes,Required,,,The features of <stdarg.h> shall not be
715715
c,MISRA-C-2012,RULE-17-2,Yes,Required,,,"Functions shall not call themselves, either directly or indirectly",A7-5-2,Statements,Import,
716716
c,MISRA-C-2012,RULE-17-3,Yes,Mandatory,,,A function shall not be declared implicitly,,Declarations,Medium,
717717
c,MISRA-C-2012,RULE-17-4,Yes,Mandatory,,,All exit paths from a function with non-void return type shall have an explicit return statement with an expression,MSC52-CPP,Statements,Medium,
718-
c,MISRA-C-2012,RULE-17-5,Yes,Advisory,,,The function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elements,,Contracts,Hard,
718+
c,MISRA-C-2012,RULE-17-5,Yes,Advisory,,,The function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elements,,Contracts6,Hard,
719719
c,MISRA-C-2012,RULE-17-6,No,Mandatory,,,The declaration of an array parameter shall not contain the static keyword between the [ ],,,,
720-
c,MISRA-C-2012,RULE-17-7,Yes,Required,,,The value returned by a function having non-void return type shall be used,A0-1-2,Contracts,Import,
720+
c,MISRA-C-2012,RULE-17-7,Yes,Required,,,The value returned by a function having non-void return type shall be used,A0-1-2,Contracts6,Import,
721721
c,MISRA-C-2012,RULE-17-8,Yes,Advisory,,,A function parameter should not be modified,,SideEffects2,Medium,
722722
c,MISRA-C-2012,RULE-18-1,Yes,Required,,,A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand,M5-0-16,Pointers1,Import,
723723
c,MISRA-C-2012,RULE-18-2,Yes,Required,,,Subtraction between pointers shall only be applied to pointers that address elements of the same array,M5-0-17,Pointers1,Import,

0 commit comments

Comments
 (0)