VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.7/util/check-format-test-negatives.c@ 97673

最後變更 在這個檔案從97673是 97372,由 vboxsync 提交於 2 年 前

libs: Switch to openssl-3.0.7, bugref:10317

檔案大小: 12.5 KB
 
1/*
2 * Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Siemens AG 2015-2022
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
11/*
12 * A collection of test cases where check-format.pl should not report issues.
13 * There are some known false positives, though, which are marked below.
14 */
15
16#define F \
17 void f() \
18 { \
19 int i; \
20 int j; \
21 \
22 return; \
23 }
24
25/*-
26 * allow extra SPC in format-tagged multi-line comment
27 */
28int f(void) /*
29 * trailing multi-line comment
30 */
31{
32 typedef int INT;
33 void v;
34 short b;
35 char c;
36 signed s;
37 unsigned u;
38 int i;
39 long l;
40 float f;
41 double d;
42 enum {} enu;
43 struct {} stru;
44 union {} un;
45 auto a;
46 extern e;
47 static int stat;
48 const int con;
49 volatile int vola;
50 register int reg;
51 OSSL_x y, *p = params;
52 int params[];
53 OSSL_PARAM * (* params []) [MAX + 1];
54 XY *(* fn)(int a, char b);
55 /*
56 * multi-line comment should not disturb detection of local decls
57 */
58 BIO1 ***b;
59 /* intra-line comment should not disturb detection of local decls */
60 unsigned k;
61
62 /* intra-line comment should not disturb detection of end of local decls */
63
64 {
65 int x; /* just decls in block */
66 }
67 if (p != (unsigned char *)
68 &(ctx->tmp[0])) {
69 i -= (p - (unsigned char *) /* do not confuse with var decl */
70 &(ctx->tmp[0]));
71 }
72 {
73 ctx->buf_off = 0; /* do not confuse with var decl */
74 return 0;
75 }
76 {
77 ctx->buf_len = EVP_EncodeBlock((unsigned char *)ctx->buf,
78 (unsigned char *)ctx->tmp, /* no decl */
79 ctx->tmp_len);
80 }
81 {
82 EVP_EncodeFinal(ctx->base64,
83 (unsigned char *)ctx->buf, &(ctx->len)); /* no decl */
84 /* push out the bytes */
85 goto again;
86 }
87 {
88 f(1, (unsigned long)2); /* no decl */
89 x;
90 }
91 {
92 char *pass_str = get_passwd(opt_srv_secret, "x");
93
94 if (pass_str != NULL) {
95 cleanse(opt_srv_secret);
96 res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_str,
97 strlen(pass_str));
98 clear_free(pass_str);
99 }
100 }
101}
102
103int g(void)
104{
105 if (ctx == NULL) { /* non-leading end-of-line comment */
106 if (/* comment after '(' */ pem_name != NULL /* comment before ')' */)
107 /* entire-line comment indent usually like for the following line */
108 return NULL; /* hanging indent also for this line after comment */
109 /* leading comment has same indentation as normal code */ stmt;
110 /* entire-line comment may have same indent as normal code */
111 }
112
113 for (;;)
114 ;
115 for (i = 0;;)
116 ;
117 for (i = 0; i < 1;)
118 ;
119 for (;;)
120 for (; i < n; i++)
121 for (;; p++)
122 ;
123 for (;;) ; /* should not trigger: space before ';' */
124 lab: ; /* should not trigger: space before ';' */
125
126#if X
127 if (1) /* bad style: just part of control structure depends on #if */
128#else
129 if (2) /*@ resulting false positive */
130#endif
131 c; /*@ resulting false positive */
132
133 if (1)
134 if (2)
135 c;
136 else
137 e;
138 else
139 f;
140 do
141 do
142 2;
143 while (1);
144 while (2);
145
146 if (1)
147 f(a, b);
148 do
149 1; while (2); /*@ more than one stmt just to construct case */
150 if (1)
151 f(a, b);
152 else
153 do
154 1;
155 while (2);
156 if (1)
157 f(a, b);
158 else do /*@ (non-brace) code before 'do' just to construct case */
159 1;
160 while (2);
161 f1234(a,
162 b); do /*@ (non-brace) code before 'do' just to construct case */
163 1;
164 while (2);
165 if (1)
166 f(a,
167 b); do /*@ (non-brace) code before 'do' just to construct case */
168 1;
169 while (2);
170 if (1)
171 f(a, b);
172 else
173 do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
174 while (2);
175
176 if (1)
177 f(a, b);
178 else
179 return;
180 if (1)
181 f(a,
182 b); else /*@ (non-brace) code before 'else' just to construct case */
183 do
184 1;
185 while (2);
186
187 if (1)
188 { /*@ brace after 'if' not on same line just to construct case */
189 c;
190 d;
191 }
192 /* this comment is correctly indented if it refers to the following line */
193 d;
194
195 if (1) {
196 2;
197 } else /*@ no brace after 'else' just to construct case */
198 3;
199 do {
200 } while (x);
201 if (1) {
202 2;
203 } else {
204 3;
205 }
206 if (4)
207 5;
208 else
209 6;
210
211 if (1) {
212 if (2) {
213 case MAC_TYPE_MAC:
214 {
215 EVP_MAC_CTX *new_mac_ctx;
216
217 if (ctx->pkey == NULL)
218 return 0;
219 }
220 break;
221 default:
222 /* This should be dead code */
223 return 0;
224 }
225 }
226 if (expr_line1
227 == expr_line2
228 && expr_line3) {
229 c1;
230 } else {
231 c;
232 d;
233 }
234 if (expr_line1
235 == expr_line2
236 && expr_line3)
237 hanging_stmt;
238}
239
240/* should not trigger: constant on LHS of comparison or assignment operator */
241X509 *x509 = NULL;
242int y = a + 1 < b;
243int ret, was_NULL = *certs == NULL;
244
245/* should not trigger: no space before binary ... operator */
246float z = 1e-6 * (-1) * b[+6] * 1e+1 * (a)->f * (long)+1
247 - (tmstart.tv_sec + tmstart.tv_nsec * 1e-9);
248struct st = {-1, 0};
249
250const OPTIONS passwd_options[] = {
251 {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
252#if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
253 {"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
254#endif
255 OPT_R_OPTIONS,
256
257 {NULL}
258};
259
260typedef * d(int)
261 x;
262typedef (int)
263x;
264typedef (int)*()
265 x;
266typedef *int *
267x;
268typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
269 (OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
270 xx;
271
272int f()
273{
274 c;
275 if (1) {
276 c;
277 }
278 c;
279 if (1)
280 if (2)
281 { /*@ brace after 'if' not on same line just to construct case */
282 c;
283 }
284 e;
285 const usign = {
286 0xDF,
287 {
288 dd
289 },
290 dd
291 };
292 const unsign = {
293 0xDF, {
294 dd
295 },
296 dd
297 };
298}
299const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
300 0xDF,
301};
302const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
303 {
304 0xDF,
305 };
306typedef
307int
308a;
309
310typedef
311struct
312{
313 int a;
314} b;
315typedef enum {
316 w = 0
317} e_type;
318typedef struct {
319 enum {
320 w = 0
321 } e_type;
322 enum {
323 w = 0
324 } e_type;
325} e;
326struct s_type {
327 enum e_type {
328 w = 0
329 };
330};
331struct s_type
332{
333 enum e_type {
334 w = 0
335 };
336 enum e2_type {
337 w = 0
338 };
339};
340
341#define X 1 + 1
342#define Y /* .. */ 2 + 2
343#define Z 3 + 3 * (*a++)
344
345static varref cmp_vars[] = { /* comment. comment? comment! */
346 {&opt_config}, {&opt_section},
347
348 {&opt_server}, {&opt_proxy}, {&opt_path},
349};
350
351#define SWITCH(x) \
352 switch (x) { \
353 case 0: \
354 break; \
355 default: \
356 break; \
357 }
358
359#define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
360 DEFAULT, NEW, FREE) \
361 static int execute_CTX_##SETN##_##GETN##_##FIELD( \
362 TEST_FIXTURE *fixture) \
363 { \
364 CTX *ctx = fixture->ctx; \
365 int (*set_fn)(CTX *ctx, TYPE) = \
366 (int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
367 /* comment */ \
368 }
369
370union un var; /* struct/union/enum in variable type */
371struct provider_store_st *f() /* struct/union/enum in function return type */
372{
373}
374static void f(struct pem_pass_data *data) /* struct/union/enum in arg list */
375{
376}
377
378static void *fun(void)
379{
380 if (pem_name != NULL)
381 /* comment */
382 return NULL;
383
384label0:
385 label1: /* allow special indent 1 for label at outermost level in body */
386 do {
387 label2:
388 size_t available_len, data_len;
389 const char *curr = txt, *next = txt;
390 char *tmp;
391
392 {
393 label3:
394 }
395 } while (1);
396
397 char *intraline_string_with_comment_delimiters_and_dbl_space = "1 /*1";
398 char *multiline_string_with_comment_delimiters_and_dbl_space = "1 /*1\
3992222222\'22222222222222222\"222222222" "33333 /*3333333333" "44 /*44444444444\
40055555555555555\
4016666";
402}
403
404ASN1_CHOICE(OSSL_CRMF_POPO) = {
405 ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
406 ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
407} ASN1_CHOICE_END(OSSL_CRMF_POPO)
408IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
409
410ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
411 ADB_ENTRY(NID_id_regCtrl_regToken,
412 ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
413 value.regToken, ASN1_UTF8STRING)),
414} ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
415 &attributetypeandvalue_default_tt, NULL);
416
417ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
418 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
419 OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
420ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
421
422void f_looong_body_200()
423{ /* function body length up to 200 lines accepted */
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 ;
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
626void f_looong_body_201()
627{ /* function body length > 200 lines, but LONG BODY marker present */
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 ;
737 ;
738 ;
739 ;
740 ;
741 ;
742 ;
743 ;
744 ;
745 ;
746 ;
747 ;
748 ;
749 ;
750 ;
751 ;
752 ;
753 ;
754 ;
755 ;
756 ;
757 ;
758 ;
759 ;
760 ;
761 ;
762 ;
763 ;
764 ;
765 ;
766 ;
767 ;
768 ;
769 ;
770 ;
771 ;
772 ;
773 ;
774 ;
775 ;
776 ;
777 ;
778 ;
779 ;
780 ;
781 ;
782 ;
783 ;
784 ;
785 ;
786 ;
787 ;
788 ;
789 ;
790 ;
791 ;
792 ;
793 ;
794 ;
795 ;
796 ;
797 ;
798 ;
799 ;
800 ;
801 ;
802 ;
803 ;
804 ;
805 ;
806 ;
807 ;
808 ;
809 ;
810 ;
811 ;
812 ;
813 ;
814 ;
815 ;
816 ;
817 ;
818 ;
819 ;
820 ;
821 ;
822 ;
823 ;
824 ;
825 ;
826 ;
827 ;
828 ;
829 ;
830}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette