check-format-test-negatives.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. * 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. * allow double space in format-tagged multi-line comment
  17. */
  18. int f(void) /*
  19. * trailing multi-line comment
  20. */
  21. {
  22. if (ctx == NULL) { /* non-leading intra-line comment */
  23. if (pem_name != NULL)
  24. /* entire-line comment indent usually like for the following line */
  25. return NULL; /* hanging indent also for this line after comment */
  26. /* leading comment has same indentation as normal code */ stmt;
  27. /* entire-line comment may have same indent as normal code */
  28. }
  29. #if X
  30. if (1) /* bad style: just part of control structure depends on #if */
  31. #else
  32. if (2) /*@ resulting false positive */
  33. #endif
  34. c; /*@ resulting false positive */
  35. if (1)
  36. if (2)
  37. c;
  38. else
  39. e;
  40. else
  41. f;
  42. do
  43. do
  44. 2;
  45. while (1);
  46. while (2);
  47. if (1)
  48. f(a, b);
  49. do
  50. 1; while (2); /*@ more than one stmt just to construct case */
  51. if (1)
  52. f(a, b);
  53. else
  54. do
  55. 1;
  56. while (2);
  57. if (1)
  58. f(a, b);
  59. else do /*@ (non-brace) code before 'do' just to construct case */
  60. 1;
  61. while (2);
  62. f1234(a,
  63. b); do /*@ (non-brace) code before 'do' just to construct case */
  64. 1;
  65. while (2);
  66. if (1)
  67. f(a,
  68. b); do /*@ (non-brace) code before 'do' just to construct case */
  69. 1;
  70. while (2);
  71. if (1)
  72. f(a, b);
  73. else
  74. do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
  75. while (2);
  76. if (1)
  77. f(a, b);
  78. else
  79. return;
  80. if (1)
  81. f(a,
  82. b); else /*@ (non-brace) code before 'else' just to construct case */
  83. do
  84. 1;
  85. while (2);
  86. if (1)
  87. { /*@ brace after 'if' not on same line just to construct case */
  88. c;
  89. d;
  90. }
  91. /* this comment is correctly indented if it refers to the following line */
  92. d;
  93. if (1) {
  94. 2;
  95. } else /*@ no brace after 'else' just to construct case */
  96. 3;
  97. do {
  98. } while (x);
  99. if (1) {
  100. 2;
  101. } else {
  102. 3;
  103. }
  104. if (4)
  105. 5;
  106. else
  107. 6;
  108. if (1) {
  109. if (2) {
  110. case MAC_TYPE_MAC:
  111. {
  112. EVP_MAC_CTX *new_mac_ctx;
  113. if (ctx->pkey == NULL)
  114. return 0;
  115. }
  116. break;
  117. default:
  118. /* This should be dead code */
  119. return 0;
  120. }
  121. }
  122. if (expr_line1
  123. == expr_line2
  124. && expr_line3) {
  125. c1;
  126. } else {
  127. c;
  128. d;
  129. }
  130. if (expr_line1
  131. == expr_line2
  132. && expr_line3)
  133. hanging_stmt;
  134. }
  135. const OPTIONS passwd_options[] = {
  136. {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
  137. #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  138. {"crypt", OPT_CRYPT, '-', "Standard Unix password algorithm (default)"},
  139. #endif
  140. OPT_R_OPTIONS,
  141. {NULL}
  142. };
  143. typedef * d(int)
  144. x;
  145. typedef (int)
  146. x;
  147. typedef (int)*()
  148. x;
  149. typedef *int *
  150. x;
  151. typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
  152. (OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
  153. xx;
  154. int f()
  155. {
  156. c;
  157. if (1) {
  158. c;
  159. }
  160. c;
  161. if (1)
  162. if (2)
  163. { /*@ brace after 'if' not on same line just to construct case */
  164. c;
  165. }
  166. e;
  167. const usign = {
  168. 0xDF,
  169. {
  170. dd
  171. },
  172. dd
  173. };
  174. const unsign = {
  175. 0xDF, {
  176. dd
  177. },
  178. dd
  179. };
  180. }
  181. const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] = {
  182. 0xDF,
  183. };
  184. const unsigned char trans_id[OSSL_CMP_TRANSACTIONID_LENGTH] =
  185. {
  186. 0xDF,
  187. };
  188. typedef
  189. int
  190. a;
  191. typedef
  192. struct
  193. {
  194. int a;
  195. } b;
  196. typedef enum {
  197. w = 0
  198. } e_type;
  199. typedef struct {
  200. enum {
  201. w = 0
  202. } e_type;
  203. enum {
  204. w = 0
  205. } e_type;
  206. } e;
  207. struct s_type {
  208. enum e_type {
  209. w = 0
  210. };
  211. };
  212. struct s_type
  213. {
  214. enum e_type {
  215. w = 0
  216. };
  217. enum e2_type {
  218. w = 0
  219. };
  220. };
  221. #define X 1 + 1
  222. #define Y /* .. */ 2 + 2
  223. #define Z 3 + 3
  224. static varref cmp_vars[] = { /* comment */
  225. {&opt_config}, {&opt_section},
  226. {&opt_server}, {&opt_proxy}, {&opt_path},
  227. };
  228. #define SWITCH(x) \
  229. switch (x) { \
  230. case 0: \
  231. break; \
  232. default: \
  233. break; \
  234. }
  235. #define DEFINE_SET_GET_BASE_TEST(PREFIX, SETN, GETN, DUP, FIELD, TYPE, ERR, \
  236. DEFAULT, NEW, FREE) \
  237. static int execute_CTX_##SETN##_##GETN##_##FIELD( \
  238. TEST_FIXTURE *fixture) \
  239. { \
  240. CTX *ctx = fixture->ctx; \
  241. int (*set_fn)(CTX *ctx, TYPE) = \
  242. (int (*)(CTX *ctx, TYPE))PREFIX##_##SETN##_##FIELD; \
  243. /* comment */ \
  244. }
  245. /* 'struct' in function header */
  246. static int f(struct pem_pass_data *pass_data)
  247. {
  248. if (pass_data == NULL)
  249. return 0;
  250. }
  251. static void *fun(void)
  252. {
  253. if (pem_name != NULL)
  254. /* comment */
  255. return NULL;
  256. do {
  257. size_t available_len, data_len;
  258. const char *curr = txt, *next = txt;
  259. char *tmp;
  260. } while (1);
  261. char *intraline_string_with_comment_delimiters_and_dbl_space = "1 /*1";
  262. char *multiline_string_with_comment_delimiters_and_dbl_space = "1 /*1\
  263. 2222222\'22222222222222222\"222222222" "33333 /*3333333333" "44 /*44444444444\
  264. 55555555555555\
  265. 6666";
  266. }
  267. ASN1_CHOICE(OSSL_CRMF_POPO) = {
  268. ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
  269. ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
  270. } ASN1_CHOICE_END(OSSL_CRMF_POPO)
  271. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
  272. ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
  273. ADB_ENTRY(NID_id_regCtrl_regToken,
  274. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  275. value.regToken, ASN1_UTF8STRING)),
  276. } ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
  277. &attributetypeandvalue_default_tt, NULL);
  278. ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
  279. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  280. OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
  281. ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
  282. void f_looong_body_200()
  283. { /* function body length up to 200 lines accepted */
  284. }
  285. void f_looong_body_201()
  286. { /* function body length > 200 lines, but LONG BODY marker present */
  287. }