test/recipes/30-test_evp_data/evppkey.txt: Change an expected KeyGen result
[openssl.git] / util / check-format-test-negatives.c
1 /*
2  * Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright Nokia 2007-2019
4  * Copyright Siemens AG 2015-2019
5  *
6  * Licensed under the Apache License 2.0 (the "License").  You may not use
7  * this file except in compliance with the License.  You can obtain a copy
8  * in the file LICENSE in the source distribution or at
9  * https://www.openssl.org/source/license.html
10  */
11
12 /*
13  * A collection of test cases where check-format.pl should not report issues.
14  * There are some known false positives, though, which are marked below.
15  */
16
17 /*-
18  * allow double space  in format-tagged multi-line comment
19  */
20 int f(void) /*
21              * trailing multi-line comment
22              */
23 {
24     if (ctx == NULL) { /* non-leading intra-line comment */
25         if (pem_name != NULL)
26             /* entire-line comment indent usually like for the following line */
27             return NULL; /* hanging indent also for this line after comment */
28         /* leading comment has same indentation as normal code */ stmt;
29         /* entire-line comment may have same indent as normal code */
30     }
31
32 #if X
33     if (1) /* bad style: just part of control structure depends on #if */
34 #else
35     if (2) /*@ resulting false positive */
36 #endif
37         c; /*@ resulting false positive */
38
39     if (1)
40         if (2)
41             c;
42         else
43             e;
44     else
45         f;
46     do
47         do
48             2;
49         while (1);
50     while (2);
51
52     if (1)
53         f(a, b);
54     do
55         1; while (2); /*@ more than one stmt just to construct case */
56     if (1)
57         f(a, b);
58     else
59         do
60             1;
61         while (2);
62     if (1)
63         f(a, b);
64     else do /*@ (non-brace) code before 'do' just to construct case */
65              1;
66         while (2);
67     f1234(a,
68           b); do /*@ (non-brace) code before 'do' just to construct case */
69                   1;
70     while (2);
71     if (1)
72         f(a,
73           b); do /*@ (non-brace) code before 'do' just to construct case */
74                   1;
75     while (2);
76     if (1)
77         f(a, b);
78     else
79         do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
80         while (2);
81
82     if (1)
83         f(a, b);
84     else
85         return;
86     if (1)
87         f(a,
88           b); else /*@ (non-brace) code before 'else' just to construct case */
89         do
90             1;
91         while (2);
92
93     if (1)
94     { /*@ brace after 'if' not on same line just to construct case */
95         c;
96         d;
97     }
98     /* this comment is correctly indented if it refers to the following line */
99     d;
100
101     if (1) {
102         2;
103     } else /*@ no brace after 'else' just to construct case */
104         3;
105     do {
106     } while (x);
107     if (1) {
108         2;
109     } else {
110         3;
111     }
112     if (4)
113         5;
114     else
115         6;
116 }
117 typedef * d(int)
118     x;
119 typedef (int)
120 x;
121 typedef (int)*()
122     x;
123 typedef *int *
124 x;
125 typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
126     (OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
127     xx;
128 int f()
129 {
130     c;
131     if (1) {
132         c;
133     }
134     c;
135     if (1)
136         if (2)
137         { /*@ brace after 'if' not on same line just to construct case */
138             c;
139         }
140     e;
141     const usign = {
142                    0xDF,
143                    {
144                     dd
145                    },
146                    dd
147     };
148     const unsign = {
149                     0xDF, {
150                            dd
151                     },
152                     dd
153     };
154 }
155 const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
156                                                                0xDF,
157 };
158 const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
159     {
160      0xDF,
161     };
162 typedef
163 int
164 a;
165
166 typedef
167 struct
168 {
169     int a;
170 } b;
171 typedef enum {
172               w = 0
173 } e_type;
174 typedef struct {
175     enum {
176           w = 0
177     } e_type;
178     enum {
179           w = 0
180     } e_type;
181 } e;
182 struct s_type {
183     enum e_type {
184                  w = 0
185     };
186 };
187 struct s_type
188 {
189     enum e_type {
190                  w = 0
191     };
192     enum e2_type {
193                   w = 0
194     };
195 };
196
197 #define X  1          + 1
198 #define Y  /* .. */ 2 + 2
199 #define Z  3          + 3
200
201 static varref cmp_vars[] = { /* comment */
202     {&opt_config}, {&opt_section},
203
204     {&opt_server}, {&opt_proxy}, {&opt_path},
205 };
206
207 #define SWITCH(x)                               \
208     switch (x) {                                \
209     case 0:                                     \
210         break;                                  \
211     default:                                    \
212         break;                                  \
213     }
214
215 #define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
216                                  DEFAULT, NEW, FREE) \
217     static int execute_CTX_##SETN##_##GETN##_##FIELD( \
218                                                      TEST_FIXTURE *fixture) \
219     { \
220         CTX *ctx = fixture->ctx; \
221         int (*set_fn)(CTX *ctx, TYPE) = \
222             (int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
223         /* comment */ \
224     }
225
226 /* 'struct' in function header */
227 static int f(struct pem_pass_data *pass_data)
228 {
229     if (pass_data == NULL)
230         return 0;
231 }
232
233 static void *fun(void)
234 {
235     if (pem_name != NULL)
236         /* comment */
237         return NULL;
238
239     do {
240         size_t available_len, data_len;
241         const char *curr = txt, *next = txt;
242         char *tmp;
243     } while (1);
244
245     char *intraline_string_with_comment_delimiters_and_dbl_space = "1  /*1";
246     char *multiline_string_with_comment_delimiters_and_dbl_space = "1  /*1\
247 2222222\'22222222222222222\"222222222" "33333  /*3333333333" "44  /*44444444444\
248 55555555555555\
249 6666";
250 }
251
252 ASN1_CHOICE(OSSL_CRMF_POPO) = {
253     ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
254     ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
255 } ASN1_CHOICE_END(OSSL_CRMF_POPO)
256 IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
257
258 ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
259     ADB_ENTRY(NID_id_regCtrl_regToken,
260               ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
261                           value.regToken, ASN1_UTF8STRING)),
262 } ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
263                &attributetypeandvalue_default_tt, NULL);
264
265 ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
266     ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
267                           OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
268 ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
269
270 void f_looong_body_200()
271 { /* function body length up to 200 lines accepted */
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472 }
473
474 void f_looong_body_201()
475 { /* function body length > 200 lines, but LONG BODY marker present */
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678 }