2 * Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Siemens AG 2015-2022
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
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.
16 #include <errno.h> /* should not report whitespace nits within <...> */
26 /* allow extra SPC in single-line comment */
28 * allow extra SPC in regular multi-line comment
31 * allow extra SPC in format-tagged multi-line comment
33 /** allow extra '*' in comment opening */
34 /*! allow extra '!' in comment opening */
36 ** allow "**" as first non-space chars of a line within multi-line comment
40 * trailing multi-line comment
62 OSSL_x y, *p = params;
64 OSSL_PARAM * (* params []) [MAX + 1];
65 XY *(* fn)(int a, char b);
67 * multi-line comment should not disturb detection of local decls
70 /* intra-line comment should not disturb detection of local decls */
73 /* intra-line comment should not disturb detection of end of local decls */
76 int x; /* just decls in block */
78 if (p != (unsigned char *)
80 i -= (p - (unsigned char *) /* do not confuse with var decl */
84 ctx->buf_off = 0; /* do not confuse with var decl */
88 ctx->buf_len = EVP_EncodeBlock((unsigned char *)ctx->buf,
89 (unsigned char *)ctx->tmp, /* no decl */
93 EVP_EncodeFinal(ctx->base64,
94 (unsigned char *)ctx->buf, &(ctx->len)); /* no decl */
95 /* push out the bytes */
99 f(1, (unsigned long)2); /* no decl */
103 char *pass_str = get_passwd(opt_srv_secret, "x");
105 if (pass_str != NULL) {
106 cleanse(opt_srv_secret);
107 res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_str,
109 clear_free(pass_str);
116 if (ctx == NULL) { /* non-leading end-of-line comment */
117 if (/* comment after '(' */ pem_name != NULL /* comment before ')' */)
118 /* entire-line comment indent usually like for the following line */
119 return NULL; /* hanging indent also for this line after comment */
120 /* leading comment has same indentation as normal code */ stmt;
121 /* entire-line comment may have same indent as normal code */
123 for (i = 0; i < n; i++)
139 for (;;) /* the only variant allowed in case of "empty" for (...) */
141 for (;;) ; /* should not trigger: space before ';' */
142 lab: ; /* should not trigger: space before ';' */
145 if (1) /* bad style: just part of control structure depends on #if */
147 if (2) /*@ resulting false positive */
149 c; /*@ resulting false positive */
167 1; while (2); /*@ more than one stmt just to construct case */
176 else do /*@ (non-brace) code before 'do' just to construct case */
180 b); do /*@ (non-brace) code before 'do' just to construct case */
185 b); do /*@ (non-brace) code before 'do' just to construct case */
191 do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
200 b); else /*@ (non-brace) code before 'else' just to construct case */
206 { /*@ brace after 'if' not on same line just to construct case */
210 /* this comment is correctly indented if it refers to the following line */
215 } else /*@ no brace after 'else' just to construct case */
233 EVP_MAC_CTX *new_mac_ctx;
235 if (ctx->pkey == NULL)
240 /* This should be dead code */
258 do { /* should not be confused with function header followed by '{' */ \
261 /* should not trigger: constant on LHS of comparison or assignment operator */
264 int ret, was_NULL = *certs == NULL;
266 /* should not trigger: missing space before ... */
267 float z = 1e-6 * (-1) * b[+6] * 1e+1 * (a)->f * (long)+1
268 - (tmstart.tv_sec + tmstart.tv_nsec * 1e-9);
270 int x = (y <<= 1) + (z <= 5.0);
272 const OPTIONS passwd_options[] = {
273 {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
274 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
275 {"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
290 typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
291 (OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
294 #define IF(cond) if (cond)
296 _Pragma("GCC diagnostic push")
297 _Pragma("GCC diagnostic pop")
299 #define CB_ERR_IF(cond, ctx, cert, depth, err) \
300 if ((cond) && ((depth) < 0 || verify_cb_cert(ctx, cert, depth, err) == 0)) \
302 static int verify_cb_crl(X509_STORE_CTX *ctx, int err)
305 return ctx->verify_cb(0, ctx);
308 #ifdef CMP_FALLBACK_EST
309 # define CMP_FALLBACK_CERT_FILE "cert.pem"
312 #define X509_OBJECT_get0_X509(obj) \
313 ((obj) == NULL || (obj)->type != X509_LU_X509 ? NULL : (obj)->data.x509)
314 #define X509_STORE_CTX_set_current_cert(ctx, x) { (ctx)->current_cert = (x); }
315 #define X509_STORE_set_ex_data(ctx, idx, data) \
316 CRYPTO_set_ex_data(&(ctx)->ex_data, (idx), (data))
318 typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx);
319 #define X509_STORE_CTX_set_error_depth(ctx, depth) \
320 { (ctx)->error_depth = (depth); }
321 #define EVP_PKEY_up_ref(x) ((x)->references++)
322 /* should not report missing blank line: */
323 DECLARE_STACK_OF(OPENSSL_CSTRING)
324 bool UTIL_iterate_dir(int (*fn)(const char *file, void *arg), void *arg,
325 const char *path, bool recursive);
326 size_t UTIL_url_encode(
329 size_t UTIL_url_encode(const char *source,
331 size_t destination_len,
332 size_t *size_needed);
344 { /*@ brace after 'if' not on same line just to construct case */
362 const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
365 const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
405 #define Y /* .. */ 2 + 2
406 #define Z 3 + 3 * (*a++)
408 static varref cmp_vars[] = { /* comment. comment? comment! */
409 {&opt_config}, {&opt_section},
411 {&opt_server}, {&opt_proxy}, {&opt_path},
422 #define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
423 DEFAULT, NEW, FREE) \
424 static int execute_CTX_##SETN##_##GETN##_##FIELD( \
425 TEST_FIXTURE *fixture) \
427 CTX *ctx = fixture->ctx; \
428 int (*set_fn)(CTX *ctx, TYPE) = \
429 (int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
433 union un var; /* struct/union/enum in variable type */
434 struct provider_store_st *f() /* struct/union/enum in function return type */
437 static void f(struct pem_pass_data *data) /* struct/union/enum in arg list */
441 static void *fun(void)
443 if (pem_name != NULL)
448 label1: /* allow special indent 1 for label at outermost level in body */
451 size_t available_len, data_len;
452 const char *curr = txt, *next = txt;
460 char *intraline_string_with_comment_delimiters_and_dbl_space = "1 /*1";
461 char *multiline_string_with_comment_delimiters_and_dbl_space = "1 /*1\
462 2222222\'22222222222222222\"222222222" "33333 /*3333333333" "44 /*44444444444\
467 ASN1_CHOICE(OSSL_CRMF_POPO) = {
468 ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
469 ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
470 } ASN1_CHOICE_END(OSSL_CRMF_POPO)
471 IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
473 ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
474 ADB_ENTRY(NID_id_regCtrl_regToken,
475 ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
476 value.regToken, ASN1_UTF8STRING)),
477 } ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
478 &attributetypeandvalue_default_tt, NULL);
480 ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
481 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
482 OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
483 ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
485 void f_looong_body_200()
486 { /* function body length up to 200 lines accepted */
689 void f_looong_body_201()
690 { /* function body length > 200 lines, but LONG BODY marker present */