adlint 1.16.0 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +471 -0
- data/MANIFEST +35 -8
- data/NEWS +50 -4
- data/bin/adlint +7 -7
- data/bin/adlint_chk +7 -7
- data/bin/adlint_cma +7 -7
- data/bin/adlint_sma +7 -7
- data/bin/adlintize +5 -5
- data/etc/mesg.d/en_US/messages.yml +3 -3
- data/etc/mesg.d/ja_JP/messages.yml +3 -3
- data/features/message_detection/E0013.feature +34 -0
- data/features/message_detection/W0007.feature +2 -0
- data/features/message_detection/W0583.feature +1 -2
- data/features/message_detection/W0641.feature +132 -0
- data/features/message_detection/W0643.feature +1 -1
- data/features/message_detection/W0644.feature +529 -0
- data/features/message_detection/W0645.feature +1 -1
- data/features/message_detection/W0649.feature +277 -0
- data/features/message_detection/W0650.feature +208 -0
- data/features/message_detection/W0697.feature +6 -0
- data/features/message_detection/W0705.feature +350 -0
- data/features/message_detection/W0707.feature +223 -0
- data/features/message_detection/W0711.feature +113 -0
- data/features/message_detection/W0712.feature +113 -0
- data/features/message_detection/W0713.feature +110 -0
- data/features/message_detection/W0714.feature +118 -0
- data/features/message_detection/W0715.feature +118 -0
- data/features/message_detection/W0716.feature +1 -0
- data/features/message_detection/W0717.feature +1 -0
- data/features/message_detection/W0718.feature +1 -0
- data/features/message_detection/W0719.feature +154 -0
- data/features/message_detection/W0723.feature +1 -2
- data/features/message_detection/W0732.feature +3 -0
- data/features/message_detection/W0733.feature +3 -0
- data/features/message_detection/W0734.feature +4 -0
- data/features/message_detection/W0735.feature +4 -0
- data/features/message_detection/W0745.feature +132 -0
- data/features/message_detection/W0780.feature +68 -0
- data/features/message_detection/W0783.feature +95 -0
- data/features/message_detection/W0792.feature +124 -0
- data/features/message_detection/W0793.feature +153 -0
- data/features/message_detection/W0794.feature +90 -0
- data/features/message_detection/W0830.feature +65 -0
- data/features/message_detection/W0833.feature +220 -0
- data/features/message_detection/W0834.feature +189 -0
- data/features/message_detection/W1026.feature +105 -0
- data/features/message_detection/W1031.feature +17 -34
- data/features/message_detection/W1039.feature +268 -0
- data/features/message_detection/W1047.feature +163 -0
- data/features/message_detection/W1066.feature +1 -0
- data/features/message_detection/W1067.feature +1 -0
- data/features/message_detection/W1068.feature +1 -0
- data/features/message_detection/W1069.feature +5 -0
- data/features/message_detection/W1070.feature +5 -0
- data/features/message_detection/W1071.feature +83 -0
- data/features/message_detection/W1073.feature +3 -2
- data/features/message_detection/W9003.feature +7 -12
- data/features/step_definitions/message_detection_steps.rb +4 -31
- data/features/support/env.rb +117 -2
- data/lib/adlint/c/branch.rb +0 -2
- data/lib/adlint/c/ctrlexpr.rb +33 -0
- data/lib/adlint/c/expr.rb +119 -31
- data/lib/adlint/c/interp.rb +44 -3
- data/lib/adlint/c/message.rb +1411 -29
- data/lib/adlint/c/object.rb +16 -2
- data/lib/adlint/c/option.rb +1 -0
- data/lib/adlint/c/parser.rb +101 -100
- data/lib/adlint/c/parser.y +3 -2
- data/lib/adlint/c/phase.rb +18 -0
- data/lib/adlint/c/resolver.rb +23 -0
- data/lib/adlint/c/syntax.rb +90 -4
- data/lib/adlint/c/type.rb +177 -110
- data/lib/adlint/cpp/macro.rb +4 -4
- data/lib/adlint/version.rb +2 -2
- data/share/demo/bad_include/test/"1/".h +0 -0
- data/share/doc/developers_guide_ja.html +3 -3
- data/share/doc/developers_guide_ja.texi +1 -1
- data/share/doc/users_guide_en.html +467 -506
- data/share/doc/users_guide_en.texi +95 -125
- data/share/doc/users_guide_ja.html +471 -518
- data/share/doc/users_guide_ja.texi +95 -133
- data/spec/spec_helper.rb +6 -0
- metadata +37 -10
@@ -33,6 +33,7 @@ Feature: W0697
|
|
33
33
|
| W0117 | 1 | 12 |
|
34
34
|
| W0697 | 1 | 12 |
|
35
35
|
| W0104 | 1 | 21 |
|
36
|
+
| W1071 | 1 | 12 |
|
36
37
|
| W0628 | 1 | 12 |
|
37
38
|
|
38
39
|
Scenario: `return' statements are only in a `if-else-if' statements chain
|
@@ -53,6 +54,7 @@ Feature: W0697
|
|
53
54
|
| W0117 | 1 | 12 |
|
54
55
|
| W0697 | 1 | 12 |
|
55
56
|
| W0104 | 1 | 21 |
|
57
|
+
| W1071 | 1 | 12 |
|
56
58
|
| W1069 | 3 | 5 |
|
57
59
|
| W0628 | 1 | 12 |
|
58
60
|
|
@@ -80,6 +82,7 @@ Feature: W0697
|
|
80
82
|
| W0117 | 1 | 12 |
|
81
83
|
| W0697 | 1 | 12 |
|
82
84
|
| W0104 | 1 | 21 |
|
85
|
+
| W1071 | 1 | 12 |
|
83
86
|
| W0628 | 1 | 12 |
|
84
87
|
|
85
88
|
Scenario: a `return' statement in non-void function
|
@@ -112,6 +115,7 @@ Feature: W0697
|
|
112
115
|
| mesg | line | column |
|
113
116
|
| W0117 | 1 | 12 |
|
114
117
|
| W0104 | 1 | 21 |
|
118
|
+
| W1071 | 1 | 12 |
|
115
119
|
| W0628 | 1 | 12 |
|
116
120
|
|
117
121
|
Scenario: no implicit termination in `if-else-if' statements chain
|
@@ -133,6 +137,7 @@ Feature: W0697
|
|
133
137
|
| mesg | line | column |
|
134
138
|
| W0117 | 1 | 12 |
|
135
139
|
| W0104 | 1 | 21 |
|
140
|
+
| W1071 | 1 | 12 |
|
136
141
|
| W0628 | 1 | 12 |
|
137
142
|
|
138
143
|
Scenario: no implicit termination with `switch' statement
|
@@ -158,6 +163,7 @@ Feature: W0697
|
|
158
163
|
| mesg | line | column |
|
159
164
|
| W0117 | 1 | 12 |
|
160
165
|
| W0104 | 1 | 21 |
|
166
|
+
| W1071 | 1 | 12 |
|
161
167
|
| W0628 | 1 | 12 |
|
162
168
|
|
163
169
|
Scenario: no implicit termination with `goto' statement
|
@@ -0,0 +1,350 @@
|
|
1
|
+
Feature: W0705
|
2
|
+
|
3
|
+
W0705 detects that an array subscript may cause out of bound access of the
|
4
|
+
array object.
|
5
|
+
|
6
|
+
Scenario: array-subscript-expression with non-constant subscript may cause
|
7
|
+
OOB access in an initializer
|
8
|
+
Given a target source named "W0705.c" with:
|
9
|
+
"""
|
10
|
+
extern int a[5];
|
11
|
+
|
12
|
+
int foo(int i)
|
13
|
+
{
|
14
|
+
if (i >= 0 && i < 5) {
|
15
|
+
int j = a[i + 1]; /* W0705 */
|
16
|
+
return j;
|
17
|
+
}
|
18
|
+
return i;
|
19
|
+
}
|
20
|
+
"""
|
21
|
+
When I successfully run `adlint W0705.c` on noarch
|
22
|
+
Then the output should exactly match with:
|
23
|
+
| mesg | line | column |
|
24
|
+
| W0118 | 1 | 12 |
|
25
|
+
| W0117 | 3 | 5 |
|
26
|
+
| W0705 | 6 | 21 |
|
27
|
+
| W0100 | 6 | 13 |
|
28
|
+
| W0104 | 3 | 13 |
|
29
|
+
| W1071 | 3 | 5 |
|
30
|
+
| W0490 | 5 | 9 |
|
31
|
+
| W0499 | 5 | 9 |
|
32
|
+
| W0502 | 5 | 9 |
|
33
|
+
| W0628 | 3 | 5 |
|
34
|
+
|
35
|
+
Scenario: array-subscript-expression with non-constant subscript may cause
|
36
|
+
OOB access in rhs operand of an assignment-expression
|
37
|
+
Given a target source named "W0705.c" with:
|
38
|
+
"""
|
39
|
+
extern int a[5];
|
40
|
+
|
41
|
+
int foo(int i)
|
42
|
+
{
|
43
|
+
int j = 0;
|
44
|
+
if (i >= 0 && i < 4) {
|
45
|
+
j = a[i - 1]; /* W0705 */
|
46
|
+
}
|
47
|
+
return j;
|
48
|
+
}
|
49
|
+
"""
|
50
|
+
When I successfully run `adlint W0705.c` on noarch
|
51
|
+
Then the output should exactly match with:
|
52
|
+
| mesg | line | column |
|
53
|
+
| W0118 | 1 | 12 |
|
54
|
+
| W0117 | 3 | 5 |
|
55
|
+
| W0705 | 7 | 17 |
|
56
|
+
| W0104 | 3 | 13 |
|
57
|
+
| W0490 | 6 | 9 |
|
58
|
+
| W0499 | 6 | 9 |
|
59
|
+
| W0502 | 6 | 9 |
|
60
|
+
| W0628 | 3 | 5 |
|
61
|
+
|
62
|
+
Scenario: array-subscript-expression with non-constant subscript may cause
|
63
|
+
OOB access in lhs operand of an assignment-expression
|
64
|
+
Given a target source named "W0705.c" with:
|
65
|
+
"""
|
66
|
+
extern int a[5];
|
67
|
+
|
68
|
+
void foo(int i)
|
69
|
+
{
|
70
|
+
if (i >= 0 && i < 3) {
|
71
|
+
a[i + 3] = 0; /* W0705 */
|
72
|
+
}
|
73
|
+
}
|
74
|
+
"""
|
75
|
+
When I successfully run `adlint W0705.c` on noarch
|
76
|
+
Then the output should exactly match with:
|
77
|
+
| mesg | line | column |
|
78
|
+
| W0118 | 1 | 12 |
|
79
|
+
| W0117 | 3 | 6 |
|
80
|
+
| W0705 | 6 | 13 |
|
81
|
+
| W0104 | 3 | 14 |
|
82
|
+
| W0490 | 5 | 9 |
|
83
|
+
| W0499 | 5 | 9 |
|
84
|
+
| W0502 | 5 | 9 |
|
85
|
+
| W0628 | 3 | 6 |
|
86
|
+
|
87
|
+
Scenario: indirection-expression with non-constant subscript may cause OOB
|
88
|
+
access in rhs operand of an assignment-expression
|
89
|
+
Given a target source named "W0705.c" with:
|
90
|
+
"""
|
91
|
+
extern int a[5];
|
92
|
+
|
93
|
+
int foo(int i)
|
94
|
+
{
|
95
|
+
int j = 0;
|
96
|
+
if (i >= 0 && i < 5) {
|
97
|
+
j = *(a + i - 1); /* W0705 */
|
98
|
+
}
|
99
|
+
return j;
|
100
|
+
}
|
101
|
+
"""
|
102
|
+
When I successfully run `adlint W0705.c` on noarch
|
103
|
+
Then the output should exactly match with:
|
104
|
+
| mesg | line | column |
|
105
|
+
| W0118 | 1 | 12 |
|
106
|
+
| W0117 | 3 | 5 |
|
107
|
+
| W9003 | 7 | 19 |
|
108
|
+
| W9003 | 7 | 23 |
|
109
|
+
| W0024 | 7 | 21 |
|
110
|
+
| W0705 | 7 | 14 |
|
111
|
+
| W0104 | 3 | 13 |
|
112
|
+
| W0490 | 6 | 9 |
|
113
|
+
| W0499 | 6 | 9 |
|
114
|
+
| W0502 | 6 | 9 |
|
115
|
+
| W0628 | 3 | 5 |
|
116
|
+
|
117
|
+
Scenario: indirection-expression with non-constant subscript may cause OOB
|
118
|
+
access in lhs operand of an assignment-expression
|
119
|
+
Given a target source named "W0705.c" with:
|
120
|
+
"""
|
121
|
+
extern int a[5];
|
122
|
+
|
123
|
+
void foo(int i)
|
124
|
+
{
|
125
|
+
if (i >= 0 && i < 5) {
|
126
|
+
*(2 + a + i - 1) = 0; /* W0705 */
|
127
|
+
}
|
128
|
+
}
|
129
|
+
"""
|
130
|
+
When I successfully run `adlint W0705.c` on noarch
|
131
|
+
Then the output should exactly match with:
|
132
|
+
| mesg | line | column |
|
133
|
+
| W0118 | 1 | 12 |
|
134
|
+
| W0117 | 3 | 6 |
|
135
|
+
| W9003 | 6 | 11 |
|
136
|
+
| W0023 | 6 | 13 |
|
137
|
+
| W9003 | 6 | 19 |
|
138
|
+
| W9003 | 6 | 23 |
|
139
|
+
| W0024 | 6 | 21 |
|
140
|
+
| W0705 | 6 | 10 |
|
141
|
+
| W0104 | 3 | 14 |
|
142
|
+
| W0490 | 5 | 9 |
|
143
|
+
| W0499 | 5 | 9 |
|
144
|
+
| W0502 | 5 | 9 |
|
145
|
+
| W0628 | 3 | 6 |
|
146
|
+
|
147
|
+
Scenario: array-subscript-expression with non-constant subscript must not
|
148
|
+
cuase OOB access in initializer
|
149
|
+
Given a target source named "W0705.c" with:
|
150
|
+
"""
|
151
|
+
extern int a[5];
|
152
|
+
|
153
|
+
int foo(int i)
|
154
|
+
{
|
155
|
+
if (i > 0 && i <= 5) {
|
156
|
+
int j = a[i - 1]; /* OK */
|
157
|
+
return j;
|
158
|
+
}
|
159
|
+
return i;
|
160
|
+
}
|
161
|
+
"""
|
162
|
+
When I successfully run `adlint W0705.c` on noarch
|
163
|
+
Then the output should exactly match with:
|
164
|
+
| mesg | line | column |
|
165
|
+
| W0118 | 1 | 12 |
|
166
|
+
| W0117 | 3 | 5 |
|
167
|
+
| W0100 | 6 | 13 |
|
168
|
+
| W0104 | 3 | 13 |
|
169
|
+
| W1071 | 3 | 5 |
|
170
|
+
| W0490 | 5 | 9 |
|
171
|
+
| W0499 | 5 | 9 |
|
172
|
+
| W0502 | 5 | 9 |
|
173
|
+
| W0628 | 3 | 5 |
|
174
|
+
|
175
|
+
Scenario: array-subscript-expression with non-constant subscript must not
|
176
|
+
cause OOB access in rhs operand of an assignment-expression
|
177
|
+
Given a target source named "W0705.c" with:
|
178
|
+
"""
|
179
|
+
extern int a[5];
|
180
|
+
|
181
|
+
int foo(int i)
|
182
|
+
{
|
183
|
+
int j = 0;
|
184
|
+
if (i >= 0 && i < 4) {
|
185
|
+
j = a[i + 1]; /* OK */
|
186
|
+
}
|
187
|
+
return j;
|
188
|
+
}
|
189
|
+
"""
|
190
|
+
When I successfully run `adlint W0705.c` on noarch
|
191
|
+
Then the output should exactly match with:
|
192
|
+
| mesg | line | column |
|
193
|
+
| W0118 | 1 | 12 |
|
194
|
+
| W0117 | 3 | 5 |
|
195
|
+
| W0104 | 3 | 13 |
|
196
|
+
| W0490 | 6 | 9 |
|
197
|
+
| W0499 | 6 | 9 |
|
198
|
+
| W0502 | 6 | 9 |
|
199
|
+
| W0628 | 3 | 5 |
|
200
|
+
|
201
|
+
Scenario: array-subscript-expression with non-constant subscript must not
|
202
|
+
cause OOB access in lhs operand of an assignment-expression
|
203
|
+
Given a target source named "W0705.c" with:
|
204
|
+
"""
|
205
|
+
extern int a[5];
|
206
|
+
|
207
|
+
void foo(int i)
|
208
|
+
{
|
209
|
+
if (i >= 0 && i < 3) {
|
210
|
+
a[i + 2] = 0; /* OK */
|
211
|
+
}
|
212
|
+
}
|
213
|
+
"""
|
214
|
+
When I successfully run `adlint W0705.c` on noarch
|
215
|
+
Then the output should exactly match with:
|
216
|
+
| mesg | line | column |
|
217
|
+
| W0118 | 1 | 12 |
|
218
|
+
| W0117 | 3 | 6 |
|
219
|
+
| W0104 | 3 | 14 |
|
220
|
+
| W0490 | 5 | 9 |
|
221
|
+
| W0499 | 5 | 9 |
|
222
|
+
| W0502 | 5 | 9 |
|
223
|
+
| W0628 | 3 | 6 |
|
224
|
+
|
225
|
+
Scenario: indirection-expression with non-constant subscript must not cause
|
226
|
+
OOB access in rhs operand of an assignment-expression
|
227
|
+
Given a target source named "W0705.c" with:
|
228
|
+
"""
|
229
|
+
extern int a[5];
|
230
|
+
|
231
|
+
int foo(int i)
|
232
|
+
{
|
233
|
+
int j = 0;
|
234
|
+
if (i > 0 && i < 6) {
|
235
|
+
j = *(a + i - 1); /* OK */
|
236
|
+
}
|
237
|
+
return j;
|
238
|
+
}
|
239
|
+
"""
|
240
|
+
When I successfully run `adlint W0705.c` on noarch
|
241
|
+
Then the output should exactly match with:
|
242
|
+
| mesg | line | column |
|
243
|
+
| W0118 | 1 | 12 |
|
244
|
+
| W0117 | 3 | 5 |
|
245
|
+
| W9003 | 7 | 19 |
|
246
|
+
| W9003 | 7 | 23 |
|
247
|
+
| W0024 | 7 | 21 |
|
248
|
+
| W0104 | 3 | 13 |
|
249
|
+
| W0490 | 6 | 9 |
|
250
|
+
| W0499 | 6 | 9 |
|
251
|
+
| W0502 | 6 | 9 |
|
252
|
+
| W0628 | 3 | 5 |
|
253
|
+
|
254
|
+
Scenario: indirection-expression with non-constant subscript must not cause
|
255
|
+
OOB access in lhs operand of an assignment-expression
|
256
|
+
Given a target source named "W0705.c" with:
|
257
|
+
"""
|
258
|
+
extern int a[5];
|
259
|
+
|
260
|
+
void foo(int i)
|
261
|
+
{
|
262
|
+
if (i >= 0 && i < 5) {
|
263
|
+
*(2 + a + i - 2) = 0; /* OK */
|
264
|
+
}
|
265
|
+
}
|
266
|
+
"""
|
267
|
+
When I successfully run `adlint W0705.c` on noarch
|
268
|
+
Then the output should exactly match with:
|
269
|
+
| mesg | line | column |
|
270
|
+
| W0118 | 1 | 12 |
|
271
|
+
| W0117 | 3 | 6 |
|
272
|
+
| W9003 | 6 | 11 |
|
273
|
+
| W0023 | 6 | 13 |
|
274
|
+
| W9003 | 6 | 19 |
|
275
|
+
| W9003 | 6 | 23 |
|
276
|
+
| W0023 | 6 | 21 |
|
277
|
+
| W0104 | 3 | 14 |
|
278
|
+
| W0490 | 5 | 9 |
|
279
|
+
| W0499 | 5 | 9 |
|
280
|
+
| W0502 | 5 | 9 |
|
281
|
+
| W0628 | 3 | 6 |
|
282
|
+
|
283
|
+
Scenario: indirection-expression with non-constant subscript should not cause
|
284
|
+
OOB access in an initializer
|
285
|
+
Given a target source named "W0705.c" with:
|
286
|
+
"""
|
287
|
+
extern int a[5];
|
288
|
+
|
289
|
+
int foo(int i)
|
290
|
+
{
|
291
|
+
if (i >= 0 && i < 5) {
|
292
|
+
int j = *(a + i++); /* OK */
|
293
|
+
int k = *(a + i - 1); /* OK */
|
294
|
+
return j;
|
295
|
+
}
|
296
|
+
return i;
|
297
|
+
}
|
298
|
+
"""
|
299
|
+
When I successfully run `adlint W0705.c` on noarch
|
300
|
+
Then the output should exactly match with:
|
301
|
+
| mesg | line | column |
|
302
|
+
| W0118 | 1 | 12 |
|
303
|
+
| W0117 | 3 | 5 |
|
304
|
+
| W9003 | 6 | 24 |
|
305
|
+
| W9003 | 7 | 23 |
|
306
|
+
| W9003 | 7 | 27 |
|
307
|
+
| W0024 | 7 | 25 |
|
308
|
+
| W0100 | 6 | 13 |
|
309
|
+
| W0100 | 7 | 13 |
|
310
|
+
| W1071 | 3 | 5 |
|
311
|
+
| W0490 | 5 | 9 |
|
312
|
+
| W0499 | 5 | 9 |
|
313
|
+
| W0502 | 5 | 9 |
|
314
|
+
| W0628 | 3 | 5 |
|
315
|
+
|
316
|
+
Scenario: indirection-expression with non-constant subscript may and should
|
317
|
+
not cause OOB access in an initializer
|
318
|
+
Given a target source named "W0705.c" with:
|
319
|
+
"""
|
320
|
+
extern int a[5];
|
321
|
+
|
322
|
+
int foo(int i)
|
323
|
+
{
|
324
|
+
if (i >= 0 && i < 5) {
|
325
|
+
int j = *(a + ++i); /* W0705 */
|
326
|
+
int k = *(a + i - 1); /* OK */
|
327
|
+
return j;
|
328
|
+
}
|
329
|
+
return i;
|
330
|
+
}
|
331
|
+
"""
|
332
|
+
When I successfully run `adlint W0705.c` on noarch
|
333
|
+
Then the output should exactly match with:
|
334
|
+
| mesg | line | column |
|
335
|
+
| W0118 | 1 | 12 |
|
336
|
+
| W0117 | 3 | 5 |
|
337
|
+
| W9003 | 6 | 23 |
|
338
|
+
| W0705 | 6 | 18 |
|
339
|
+
| W9003 | 7 | 23 |
|
340
|
+
| W9003 | 7 | 27 |
|
341
|
+
| W0024 | 7 | 25 |
|
342
|
+
| W0100 | 6 | 13 |
|
343
|
+
| W0100 | 7 | 13 |
|
344
|
+
| W1071 | 3 | 5 |
|
345
|
+
| W0490 | 5 | 9 |
|
346
|
+
| W0499 | 5 | 9 |
|
347
|
+
| W0502 | 5 | 9 |
|
348
|
+
| W0628 | 3 | 5 |
|
349
|
+
|
350
|
+
# vim:ts=2:sw=2:sts=2:et:
|
@@ -0,0 +1,223 @@
|
|
1
|
+
Feature: W0707
|
2
|
+
|
3
|
+
W0707 detects that a constant-expression array subscript must cause out of
|
4
|
+
bound access of the array object.
|
5
|
+
|
6
|
+
Scenario: array-subscript-expression with constant subscript must cause OOB
|
7
|
+
access in an initializer
|
8
|
+
Given a target source named "W0707.c" with:
|
9
|
+
"""
|
10
|
+
extern int a[5];
|
11
|
+
|
12
|
+
int foo(void)
|
13
|
+
{
|
14
|
+
int i = a[5]; /* W0707 */
|
15
|
+
return i;
|
16
|
+
}
|
17
|
+
"""
|
18
|
+
When I successfully run `adlint W0707.c` on noarch
|
19
|
+
Then the output should exactly match with:
|
20
|
+
| mesg | line | column |
|
21
|
+
| W0118 | 1 | 12 |
|
22
|
+
| W0117 | 3 | 5 |
|
23
|
+
| W0707 | 5 | 15 |
|
24
|
+
| W0100 | 5 | 9 |
|
25
|
+
| W0628 | 3 | 5 |
|
26
|
+
|
27
|
+
Scenario: array-subscript-expression with constant subscript must cause OOB
|
28
|
+
access in rhs operand of an assignment-expression
|
29
|
+
Given a target source named "W0707.c" with:
|
30
|
+
"""
|
31
|
+
extern int a[5];
|
32
|
+
|
33
|
+
int foo(void)
|
34
|
+
{
|
35
|
+
int i = 0;
|
36
|
+
i = a[-1]; /* W0707 */
|
37
|
+
return i;
|
38
|
+
}
|
39
|
+
"""
|
40
|
+
When I successfully run `adlint W0707.c` on noarch
|
41
|
+
Then the output should exactly match with:
|
42
|
+
| mesg | line | column |
|
43
|
+
| W0118 | 1 | 12 |
|
44
|
+
| W0117 | 3 | 5 |
|
45
|
+
| W0707 | 6 | 11 |
|
46
|
+
| W0628 | 3 | 5 |
|
47
|
+
|
48
|
+
Scenario: array-subscript-expression with constant subscript must cause OOB
|
49
|
+
access in lhs operand of an assignment-expression
|
50
|
+
Given a target source named "W0707.c" with:
|
51
|
+
"""
|
52
|
+
extern int a[5];
|
53
|
+
|
54
|
+
void foo(int i)
|
55
|
+
{
|
56
|
+
a[5] = i; /* W0707 */
|
57
|
+
}
|
58
|
+
"""
|
59
|
+
When I successfully run `adlint W0707.c` on noarch
|
60
|
+
Then the output should exactly match with:
|
61
|
+
| mesg | line | column |
|
62
|
+
| W0118 | 1 | 12 |
|
63
|
+
| W0117 | 3 | 6 |
|
64
|
+
| W0707 | 5 | 7 |
|
65
|
+
| W0104 | 3 | 14 |
|
66
|
+
| W0628 | 3 | 6 |
|
67
|
+
|
68
|
+
Scenario: indirection-expression with constant subscript must cause OOB
|
69
|
+
access in rhs operand of an assignment-expression
|
70
|
+
Given a target source named "W0707.c" with:
|
71
|
+
"""
|
72
|
+
extern int a[5];
|
73
|
+
|
74
|
+
int foo(void)
|
75
|
+
{
|
76
|
+
int i = 0;
|
77
|
+
i = *(a + 5 - 6); /* W0707 */
|
78
|
+
return i;
|
79
|
+
}
|
80
|
+
"""
|
81
|
+
When I successfully run `adlint W0707.c` on noarch
|
82
|
+
Then the output should exactly match with:
|
83
|
+
| mesg | line | column |
|
84
|
+
| W0118 | 1 | 12 |
|
85
|
+
| W0117 | 3 | 5 |
|
86
|
+
| W9003 | 6 | 15 |
|
87
|
+
| W0023 | 6 | 13 |
|
88
|
+
| W9003 | 6 | 19 |
|
89
|
+
| W0023 | 6 | 17 |
|
90
|
+
| W0707 | 6 | 10 |
|
91
|
+
| W0628 | 3 | 5 |
|
92
|
+
|
93
|
+
Scenario: indirection-expression with constant subscript must cause OOB
|
94
|
+
access in lhs operand of an assignment-expression
|
95
|
+
Given a target source named "W0707.c" with:
|
96
|
+
"""
|
97
|
+
extern int a[5];
|
98
|
+
|
99
|
+
void foo(int i)
|
100
|
+
{
|
101
|
+
*(a - 1 + 6) = i; /* W0707 */
|
102
|
+
}
|
103
|
+
"""
|
104
|
+
When I successfully run `adlint W0707.c` on noarch
|
105
|
+
Then the output should exactly match with:
|
106
|
+
| mesg | line | column |
|
107
|
+
| W0118 | 1 | 12 |
|
108
|
+
| W0117 | 3 | 6 |
|
109
|
+
| W9003 | 5 | 11 |
|
110
|
+
| W0024 | 5 | 9 |
|
111
|
+
| W9003 | 5 | 15 |
|
112
|
+
| W0023 | 5 | 13 |
|
113
|
+
| W0707 | 5 | 6 |
|
114
|
+
| W0104 | 3 | 14 |
|
115
|
+
| W0628 | 3 | 6 |
|
116
|
+
|
117
|
+
Scenario: array-subscript-expression with constant subscript must not cause
|
118
|
+
OOB access in an initializer
|
119
|
+
Given a target source named "W0707.c" with:
|
120
|
+
"""
|
121
|
+
extern int a[5];
|
122
|
+
|
123
|
+
int foo(void)
|
124
|
+
{
|
125
|
+
int i = a[3]; /* OK */
|
126
|
+
return i;
|
127
|
+
}
|
128
|
+
"""
|
129
|
+
When I successfully run `adlint W0707.c` on noarch
|
130
|
+
Then the output should exactly match with:
|
131
|
+
| mesg | line | column |
|
132
|
+
| W0118 | 1 | 12 |
|
133
|
+
| W0117 | 3 | 5 |
|
134
|
+
| W0100 | 5 | 9 |
|
135
|
+
| W0628 | 3 | 5 |
|
136
|
+
|
137
|
+
Scenario: array-subscript-expression with constant subscript must not cause
|
138
|
+
OOB access in rhs operand of an assignment-expression
|
139
|
+
Given a target source named "W0707.c" with:
|
140
|
+
"""
|
141
|
+
extern int a[5];
|
142
|
+
|
143
|
+
int foo(void)
|
144
|
+
{
|
145
|
+
int i = 0;
|
146
|
+
i = a[0]; /* OK */
|
147
|
+
return i;
|
148
|
+
}
|
149
|
+
"""
|
150
|
+
When I successfully run `adlint W0707.c` on noarch
|
151
|
+
Then the output should exactly match with:
|
152
|
+
| mesg | line | column |
|
153
|
+
| W0118 | 1 | 12 |
|
154
|
+
| W0117 | 3 | 5 |
|
155
|
+
| W0628 | 3 | 5 |
|
156
|
+
|
157
|
+
Scenario: array-subscript-expression with constant subscript must not cause
|
158
|
+
OOB access in lhs operand of an assignment-expression
|
159
|
+
Given a target source named "W0707.c" with:
|
160
|
+
"""
|
161
|
+
extern int a[5];
|
162
|
+
|
163
|
+
void foo(int i)
|
164
|
+
{
|
165
|
+
a[4] = i; /* OK */
|
166
|
+
}
|
167
|
+
"""
|
168
|
+
When I successfully run `adlint W0707.c` on noarch
|
169
|
+
Then the output should exactly match with:
|
170
|
+
| mesg | line | column |
|
171
|
+
| W0118 | 1 | 12 |
|
172
|
+
| W0117 | 3 | 6 |
|
173
|
+
| W0104 | 3 | 14 |
|
174
|
+
| W0628 | 3 | 6 |
|
175
|
+
|
176
|
+
Scenario: indirection-expression with constant subscript must not cause OOB
|
177
|
+
access in rhs operand of an assignment-expression
|
178
|
+
Given a target source named "W0707.c" with:
|
179
|
+
"""
|
180
|
+
extern int a[5];
|
181
|
+
|
182
|
+
int foo(void)
|
183
|
+
{
|
184
|
+
int i = 0;
|
185
|
+
i = *(a - 2 + 3); /* OK */
|
186
|
+
return i;
|
187
|
+
}
|
188
|
+
"""
|
189
|
+
When I successfully run `adlint W0707.c` on noarch
|
190
|
+
Then the output should exactly match with:
|
191
|
+
| mesg | line | column |
|
192
|
+
| W0118 | 1 | 12 |
|
193
|
+
| W0117 | 3 | 5 |
|
194
|
+
| W9003 | 6 | 15 |
|
195
|
+
| W0023 | 6 | 13 |
|
196
|
+
| W9003 | 6 | 19 |
|
197
|
+
| W0023 | 6 | 17 |
|
198
|
+
| W0628 | 3 | 5 |
|
199
|
+
|
200
|
+
Scenario: indirection-expression with constant subscript must not cause OOB
|
201
|
+
access in lhs operand of an assignment-expression
|
202
|
+
Given a target source named "W0707.c" with:
|
203
|
+
"""
|
204
|
+
extern int a[5];
|
205
|
+
|
206
|
+
void foo(int i)
|
207
|
+
{
|
208
|
+
*(a + 4 - 1) = i; /* OK */
|
209
|
+
}
|
210
|
+
"""
|
211
|
+
When I successfully run `adlint W0707.c` on noarch
|
212
|
+
Then the output should exactly match with:
|
213
|
+
| mesg | line | column |
|
214
|
+
| W0118 | 1 | 12 |
|
215
|
+
| W0117 | 3 | 6 |
|
216
|
+
| W9003 | 5 | 11 |
|
217
|
+
| W0023 | 5 | 9 |
|
218
|
+
| W9003 | 5 | 15 |
|
219
|
+
| W0024 | 5 | 13 |
|
220
|
+
| W0104 | 3 | 14 |
|
221
|
+
| W0628 | 3 | 6 |
|
222
|
+
|
223
|
+
# vim:ts=2:sw=2:sts=2:et:
|