-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtest.c
112 lines (89 loc) · 1.84 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
int f1(int *p) { // NON_COMPLIANT
return *p;
}
int f2(const int *p) { // COMPLIANT
return *p;
}
int f3(int *const p) { // NON_COMPLIANT
return *p;
}
int f4(int a[5]) { // NON_COMPLIANT
int b = a[0];
return b;
}
int f5(const int a[5]) { // COMPLIANT
return a[0];
}
int f6(int a[5]) { // COMPLIANT
a[2] = a[1];
return a[0];
}
int f7(int *p1) { // COMPLIANT
int *v1 = p1; // NON_COMPLIANT
return v1[0];
}
int f8(int *p1) { // COMPLIANT
int *v1 = 0; // NON_COMPLIANT
int *v2 = p1; // NON_COMPLIANT
return v1[0];
}
int f9(int *p1) { // COMPLIANT
int *v1 = p1; // COMPLIANT
*v1 = 0;
return v1[0];
}
int f10(int *p1) { // COMPLIANT
return f8(p1);
}
int f11(int *p1) { // NON_COMPLIANT
return f2(p1);
}
char *f12(char *p1) { // NON_COMPLIANT
return p1;
}
char *const f13(char *const p1) { // NON_COMPLIANT
return p1;
}
char *f14(char *p1) { // NON_COMPLIANT
int v1 = p1[0] + 1;
char *v2 = 0; // NON_COMPLIANT
return v2;
}
const char *f15(char *p1) { // NON_COMPLIANT
const char *v1 = p1; // COMPLIANT
return v1;
}
char *f16(char *p1) { // NON_COMPLIANT
return ++p1;
}
int f17(char *p1) { // NON_COMPLIANT
p1++;
return 0;
}
#include <stdint.h>
int16_t
test_r(int16_t *value) { // COMPLIANT - ignored because of the use of ASM
int16_t result;
struct S {
int *x; // COMPLIANT - ignored because of the use of ASM
struct S2 {
int *y; // COMPLIANT - ignored because of the use of ASM
} s2;
};
__asm__("movb %bh (%eax)");
return result;
}
struct S {
int x;
};
void test_struct(struct S *s) { // COMPLIANT
s->x = 1;
}
void test_struct_2(struct S *s) { // NON_COMPLIANT - could be const
s = 0;
}
void test_no_body(int *p); // COMPLIANT - no body, so cannot evaluate whether it
// should be const
void increment(int *p) { // COMPLIANT
*p++ = 1;
}