Fix grammar in certificates.txt
[openssl.git] / util / check-format-test-negatives.c
1 /*
2  * Copyright 2007-2021 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 extra SPC in format-tagged multi-line comment
19  */
20 int f(void) /*
21              * trailing multi-line comment
22              */
23 {
24     if (ctx == NULL) {    /* non-leading end-of-line comment */
25         if (/* comment after '(' */ pem_name != NULL /* comment before ')' */)
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     for (;;)
33         ;
34     for (i = 0;;)
35         ;
36     for (i = 0; i < 1;)
37         ;
38
39 #if X
40     if (1) /* bad style: just part of control structure depends on #if */
41 #else
42     if (2) /*@ resulting false positive */
43 #endif
44         c; /*@ resulting false positive */
45
46     if (1)
47         if (2)
48             c;
49         else
50             e;
51     else
52         f;
53     do
54         do
55             2;
56         while (1);
57     while (2);
58
59     if (1)
60         f(a, b);
61     do
62         1; while (2); /*@ more than one stmt just to construct case */
63     if (1)
64         f(a, b);
65     else
66         do
67             1;
68         while (2);
69     if (1)
70         f(a, b);
71     else do /*@ (non-brace) code before 'do' just to construct case */
72              1;
73         while (2);
74     f1234(a,
75           b); do /*@ (non-brace) code before 'do' just to construct case */
76                   1;
77     while (2);
78     if (1)
79         f(a,
80           b); do /*@ (non-brace) code before 'do' just to construct case */
81                   1;
82     while (2);
83     if (1)
84         f(a, b);
85     else
86         do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
87         while (2);
88
89     if (1)
90         f(a, b);
91     else
92         return;
93     if (1)
94         f(a,
95           b); else /*@ (non-brace) code before 'else' just to construct case */
96         do
97             1;
98         while (2);
99
100     if (1)
101     { /*@ brace after 'if' not on same line just to construct case */
102         c;
103         d;
104     }
105     /* this comment is correctly indented if it refers to the following line */
106     d;
107
108     if (1) {
109         2;
110     } else /*@ no brace after 'else' just to construct case */
111         3;
112     do {
113     } while (x);
114     if (1) {
115         2;
116     } else {
117         3;
118     }
119     if (4)
120         5;
121     else
122         6;
123
124     if (1) {
125         if (2) {
126         case MAC_TYPE_MAC:
127             {
128                 EVP_MAC_CTX *new_mac_ctx;
129
130                 if (ctx->pkey == NULL)
131                     return 0;
132             }
133             break;
134         default:
135             /* This should be dead code */
136             return 0;
137         }
138     }
139     if (expr_line1
140         == expr_line2
141             && expr_line3) {
142         c1;
143     } else {
144         c;
145         d;
146     }
147     if (expr_line1
148         == expr_line2
149             && expr_line3)
150         hanging_stmt;
151 }
152
153 /* should not trigger: constant on LHS of comparison or assignment operator */
154 X509 *x509 = NULL;
155 int y = a + 1 < b;
156
157 const OPTIONS passwd_options[] = {
158     {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
159 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
160     {"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
161 #endif
162     OPT_R_OPTIONS,
163
164     {NULL}
165 };
166
167 typedef * d(int)
168     x;
169 typedef (int)
170 x;
171 typedef (int)*()
172     x;
173 typedef *int *
174 x;
175 typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
176     (OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
177     xx;
178 int f()
179 {
180     c;
181     if (1) {
182         c;
183     }
184     c;
185     if (1)
186         if (2)
187         { /*@ brace after 'if' not on same line just to construct case */
188             c;
189         }
190     e;
191     const usign = {
192                    0xDF,
193                    {
194                     dd
195                    },
196                    dd
197     };
198     const unsign = {
199                     0xDF, {
200                            dd
201                     },
202                     dd
203     };
204 }
205 const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
206                                                                0xDF,
207 };
208 const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
209     {
210      0xDF,
211     };
212 typedef
213 int
214 a;
215
216 typedef
217 struct
218 {
219     int a;
220 } b;
221 typedef enum {
222               w = 0
223 } e_type;
224 typedef struct {
225     enum {
226           w = 0
227     } e_type;
228     enum {
229           w = 0
230     } e_type;
231 } e;
232 struct s_type {
233     enum e_type {
234                  w = 0
235     };
236 };
237 struct s_type
238 {
239     enum e_type {
240                  w = 0
241     };
242     enum e2_type {
243                   w = 0
244     };
245 };
246
247 #define X  1          + 1
248 #define Y  /* .. */ 2 + 2
249 #define Z  3          + 3 * (*a++)
250
251 static varref cmp_vars[] = { /* comment.  comment?  comment!  */
252     {&opt_config}, {&opt_section},
253
254     {&opt_server}, {&opt_proxy}, {&opt_path},
255 };
256
257 #define SWITCH(x)                               \
258     switch (x) {                                \
259     case 0:                                     \
260         break;                                  \
261     default:                                    \
262         break;                                  \
263     }
264
265 #define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
266                                  DEFAULT, NEW, FREE) \
267     static int execute_CTX_##SETN##_##GETN##_##FIELD( \
268                                                      TEST_FIXTURE *fixture) \
269     { \
270         CTX *ctx = fixture->ctx; \
271         int (*set_fn)(CTX *ctx, TYPE) = \
272             (int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
273         /* comment */ \
274     }
275
276 union un var; /* struct/union/enum in variable type */
277 struct provider_store_st *f() /* struct/union/enum in function return type */
278 {
279 }
280 static void f(struct pem_pass_data *data) /* struct/union/enum in arg list */
281 {
282 }
283
284 static void *fun(void)
285 {
286     if (pem_name != NULL)
287         /* comment */
288         return NULL;
289
290 label0:
291  label1: /* allow special indent 1 for label at outermost level in body */
292     do {
293     label2:
294         size_t available_len, data_len;
295         const char *curr = txt, *next = txt;
296         char *tmp;
297
298         {
299         label3:
300         }
301     } while (1);
302
303     char *intraline_string_with_comment_delimiters_and_dbl_space = "1  /*1";
304     char *multiline_string_with_comment_delimiters_and_dbl_space = "1  /*1\
305 2222222\'22222222222222222\"222222222" "33333  /*3333333333" "44  /*44444444444\
306 55555555555555\
307 6666";
308 }
309
310 ASN1_CHOICE(OSSL_CRMF_POPO) = {
311     ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
312     ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
313 } ASN1_CHOICE_END(OSSL_CRMF_POPO)
314 IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
315
316 ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
317     ADB_ENTRY(NID_id_regCtrl_regToken,
318               ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
319                           value.regToken, ASN1_UTF8STRING)),
320 } ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
321                &attributetypeandvalue_default_tt, NULL);
322
323 ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
324     ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
325                           OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
326 ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
327
328 void f_looong_body_200()
329 { /* function body length up to 200 lines accepted */
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     ;
475     ;
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 void f_looong_body_201()
533 { /* function body length > 200 lines, but LONG BODY marker present */
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     ;
679     ;
680     ;
681     ;
682     ;
683     ;
684     ;
685     ;
686     ;
687     ;
688     ;
689     ;
690     ;
691     ;
692     ;
693     ;
694     ;
695     ;
696     ;
697     ;
698     ;
699     ;
700     ;
701     ;
702     ;
703     ;
704     ;
705     ;
706     ;
707     ;
708     ;
709     ;
710     ;
711     ;
712     ;
713     ;
714     ;
715     ;
716     ;
717     ;
718     ;
719     ;
720     ;
721     ;
722     ;
723     ;
724     ;
725     ;
726     ;
727     ;
728     ;
729     ;
730     ;
731     ;
732     ;
733     ;
734     ;
735     ;
736 }