forked from openssl/openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-format-test-positives.c
351 lines (344 loc) · 10.2 KB
/
check-format-test-positives.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*
* Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
* Copyright Siemens AG 2015-2022
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* This demonstrates/tests cases where check-format.pl should report issues.
* Some of the reports are due to sanity checks for proper nesting of comment
* delimiters and parenthesis-like symbols, e.g., on unexpected/unclosed braces.
*/
/*
* The '@'s after '*' are used for self-tests: they mark lines containing
* a single flaw that should be reported. Normally it should be reported
* while handling the given line, but in case of delayed checks there is a
* following digit indicating the number of reports expected for this line.
*/
/* For each of the following set of lines the tool should complain once */
/*@ tab character: */
/*@ intra-line carriage return character: */
/*@ non-printable ASCII character: */
/*@ non-ASCII character: ä */
/*@ whitespace at EOL: */
// /*@ end-of-line comment style not allowed (for C90 compatibility) */
/*@0 intra-line comment indent off by 1, reported unless sloppy-cmt */
/*X */ /*@2 no space nor '*' after comment start, reported unless sloppy-spc */
/* X*/ /*@ no space before comment end , reported unless sloppy-spc */
/*@ comment starting delimiter: /* inside intra-line comment */
/*@0
*@ above multi-line comment start indent off by 1, reported unless sloppy-cmt; this comment line is too long
*@ multi-line comment indent further off by 1 relative to comment start
*@ multi-line comment ending with text on last line */
/*@2 multi-line comment starting with text on first line
*@ comment starting delimiter: /* inside multi-line comment
*@ multi-line comment indent off by -1
*X*@ no spc after leading '*' in multi-line comment, reported unless sloppy-spc
*@0 more than two spaces after . in comment, reported unless sloppy-spc
*@0 more than two spaces after ? in comment, reported unless sloppy-spc
*@0 more than two spaces after ! in comment, reported unless sloppy-spc
*/ /*@ multi-line comment end indent off by -1 (relative to comment start) */
*/ /*@ unexpected comment ending delimiter outside comment */
/*@ comment line is 4 columns tooooooooooooooooo wide, reported unless sloppy-len */
/*@ comment line is 5 columns toooooooooooooooooooooooooooooooooooooooooooooo wide */
#define X 1 /*@0 extra space false negative due to coincidence */
#define Y 2 /*@ indent of preprocessor directive off by 1 (must be 0) */
typedef struct { /*@0 extra space in code, reported unless sloppy-spc */
enum { /*@1 extra space in comment, reported unless sloppy-spc */
w = 0 /*@ hanging expr indent off by 1, or 3 for lines after '{' */
&& 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */
x = 1, /*@ hanging expr indent off by -1 */
y,z /*@ no space after ',', reported unless sloppy-spc */
} e_member ; /*@ space before ';', reported unless sloppy-spc */
int v[1; /*@ unclosed bracket in type declaration */
union { /*@ statement/type declaration indent off by -1 */
struct{} s; /*@ no space before '{', reported unless sloppy-spc */
}u_member; /*@ no space after '}', reported unless sloppy-spc */
} s_type; /*@ statement/type declaration indent off by 4 */
int* somefunc(); /*@ no space before '*' in type decl, r unless sloppy-spc */
void main(int n) { /*@ opening brace at end of function definition header */
for (;;n++) { /*@ no space after ';', reported unless sloppy-spc */
return; /*@0 (1-line) single statement in braces */
}} /*@2 code after '}' outside expr */
} /*@ unexpected closing brace (too many '}') outside expr */
) /*@ unexpected closing paren outside expr */
#endif /*@ unexpected #endif */
int f (int a, /*@ space after fn before '(', reported unless sloppy-spc */
int b, /*@ hanging expr indent off by -1 */
long I) /*@ single-letter name 'I' */
{ int /*@ code after '{' opening a block */
xx = 1) + /*@ unexpected closing parenthesis */
0L < /*@ constant on LHS of comparison operator */
a] - /*@ unexpected closing bracket */
3: * /*@ unexpected ':' (without preceding '?') within expr */
4}; /*@ unexpected closing brace within expression */
char y[] = { /*@0 unclosed brace within initializer/enum expression */
1* 1, /*@ no space etc. before '*', reported unless sloppy-spc */
2, /*@ hanging expr indent (for lines after '{') off by 1 */
(xx /*@0 unclosed parenthesis in expression */
? y /*@0 unclosed '? (conditional expression) */
[0; /*@4 unclosed bracket in expression */
/*@ blank line within local decls */
s_type s; /*@2 local variable declaration indent off by -1 */
t_type t; /*@ local variable declaration indent again off by -1 */
/* */ /*@0 missing blank line after local decls */
somefunc(a, /*@2 statement indent off by -1 */
"aligned" /*@ expr indent off by -2 accepted if sloppy-hang */ "right"
, b, /*@ expr indent off by -1 */
b, /*@ expr indent as on line above, accepted if sloppy-hang */
b, /*@ expr indent off -8 but @ extra indent accepted if sloppy-hang */
"again aligned" /*@ expr indent off by -9 (left of stmt indent, */ "right",
abc == /*@ .. so reported also with sloppy-hang; this line is too long */ 456
# define MAC(A) (A) /*@ nesting indent of preprocessor directive off by 1 */
? 1 /*@ hanging expr indent off by 1 */
: 2); /*@ hanging expr indent off by 2, or 1 for leading ':' */
if(a /*@ no space after 'if', reported unless sloppy-spc */
/*@0 intra-line comment indent off by -1 (not: by 3 due to '&&') */
&& ! 0 /*@2 space after '!', reported unless sloppy-spc */
|| b == /*@ hanging expr indent off by 2, or -2 for leading '||' */
(xx+= 2) + /*@ no space before '+=', reported unless sloppy-spc */
(a^ 1) + /*@ no space before '^', reported unless sloppy-spc */
a %2 / /*@ no space after '%', reported unless sloppy-spc */
1 +/* */ /*@ no space before comment, reported unless sloppy-spc */
/* */+ /*@ no space after comment, reported unless sloppy-spc */
s. e_member) /*@ space after '.', reported unless sloppy-spc */
xx = a + b /*@ extra single-statement indent off by 1 */
+ 0; /*@ two times extra single-statement indent off by 3 */
if (a ++) /*@ space before postfix '++', reported unless sloppy-spc */
{ /*@ {' not on same line as preceding 'if' */
c; /*@0 single stmt in braces, reported on 1-stmt */
} else /*@ no '{' on same line after '} else' */
{ /*@ statement indent off by 2 */
d; /*@0 single stmt in braces, reported on 1-stmt */
} /*@ statement indent off by 6 */
if (1) f(a, /*@ (non-brace) code after end of 'if' condition */
b); else /*@ (non-brace) code before 'else' */
do f(c, c); /*@ (non-brace) code after 'do' */
while ( 2); /*@ space after '(', reported unless sloppy-spc */
b; c; /*@ more than one statement per line */
outer: /*@ outer label special indent off by 1 */
do{ /*@ no space before '{', reported unless sloppy-spc */
inner: /*@ inner label normal indent off by 1 */
f (3, /*@ space after fn before '(', reported unless sloppy-spc */
4); /*@0 false negative: should report single stmt in braces */
} /*@0 'while' not on same line as preceding '}' */
while (a+ 0); /*@2 no space before '+', reported unless sloppy-spc */
switch (b ) { /*@ space before ')', reported unless sloppy-spc */
case 1: /*@ 'case' special statement indent off by -1 */
case(2): /*@ no space after 'case', reported unless sloppy-spc */
default: ; /*@ code after 'default:' */
} /*@ statement indent off by -4 */
return( /*@ no space after 'return', reported unless sloppy-spc */
x); } /*@ code before block-level '}' */
/* Here the tool should stop complaining apart from the below issues at EOF */
void f_looong_body()
{
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
; /*@ 2 essentially blank lines before, if !sloppy-spc */
} /*@ function body length > 200 lines */
#if 0 /*@0 unclosed #if */
struct t { /*@0 unclosed brace at decl/block level */
enum { /*@0 unclosed brace at enum/expression level */
v = (1 /*@0 unclosed parenthesis */
etyp /*@0 blank line follows just before EOF, if !sloppy-spc: */