1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * Copyright Siemens AG 2015-2022 4e1051a39Sopenharmony_ci * 5e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 6e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 7e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 8e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 9e1051a39Sopenharmony_ci */ 10e1051a39Sopenharmony_ci 11e1051a39Sopenharmony_ci/* 12e1051a39Sopenharmony_ci * This demonstrates/tests cases where check-format.pl should report issues. 13e1051a39Sopenharmony_ci * Some of the reports are due to sanity checks for proper nesting of comment 14e1051a39Sopenharmony_ci * delimiters and parenthesis-like symbols, e.g., on unexpected/unclosed braces. 15e1051a39Sopenharmony_ci */ 16e1051a39Sopenharmony_ci 17e1051a39Sopenharmony_ci/* 18e1051a39Sopenharmony_ci * The '@'s after '*' are used for self-tests: they mark lines containing 19e1051a39Sopenharmony_ci * a single flaw that should be reported. Normally it should be reported 20e1051a39Sopenharmony_ci * while handling the given line, but in case of delayed checks there is a 21e1051a39Sopenharmony_ci * following digit indicating the number of reports expected for this line. 22e1051a39Sopenharmony_ci */ 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_ci/* For each of the following set of lines the tool should complain once */ 25e1051a39Sopenharmony_ci/*@ tab character: */ 26e1051a39Sopenharmony_ci/*@ intra-line carriage return character: 27e1051a39Sopenharmony_ci */ 28e1051a39Sopenharmony_ci/*@ non-printable ASCII character: */ 29e1051a39Sopenharmony_ci/*@ non-ASCII character: ä */ 30e1051a39Sopenharmony_ci/*@ whitespace at EOL: */ 31e1051a39Sopenharmony_ci// /*@ end-of-line comment style not allowed (for C90 compatibility) */ 32e1051a39Sopenharmony_ci /*@0 intra-line comment indent off by 1, reported unless sloppy-cmt */ 33e1051a39Sopenharmony_ci/*X */ /*@2 missing spc or '*' after comment start reported unless sloppy-spc */ 34e1051a39Sopenharmony_ci/* X*/ /*@ missing space before comment end , reported unless sloppy-spc */ 35e1051a39Sopenharmony_ci/*@ comment starting delimiter: /* inside intra-line comment */ 36e1051a39Sopenharmony_ci /*@0 37e1051a39Sopenharmony_ci *@ above multi-line comment start indent off by 1, reported unless sloppy-cmt; this comment line is too long 38e1051a39Sopenharmony_ci *@ multi-line comment indent further off by 1 relative to comment start 39e1051a39Sopenharmony_ci *@ multi-line comment ending with text on last line */ 40e1051a39Sopenharmony_ci/*@2 multi-line comment starting with text on first line 41e1051a39Sopenharmony_ci *@ comment starting delimiter: /* inside multi-line comment 42e1051a39Sopenharmony_ci*@ multi-line comment indent off by -1 43e1051a39Sopenharmony_ci *X*@ no spc after leading '*' in multi-line comment, reported unless sloppy-spc 44e1051a39Sopenharmony_ci *@0 more than two spaces after . in comment, no more reported 45e1051a39Sopenharmony_ci *@0 more than two spaces after ? in comment, no more reported 46e1051a39Sopenharmony_ci *@0 more than two spaces after ! in comment, no more reported 47e1051a39Sopenharmony_ci*/ /*@ multi-line comment end indent off by -1 (relative to comment start) */ 48e1051a39Sopenharmony_ci*/ /*@ unexpected comment ending delimiter outside comment */ 49e1051a39Sopenharmony_ci/*- '-' for formatted comment not allowed in intra-line comment */ 50e1051a39Sopenharmony_ci/*@ comment line is 4 columns tooooooooooooooooo wide, reported unless sloppy-len */ 51e1051a39Sopenharmony_ci/*@ comment line is 5 columns toooooooooooooooooooooooooooooooooooooooooooooo wide */ 52e1051a39Sopenharmony_ci#if ~0 /*@ '#if' with constant condition */ 53e1051a39Sopenharmony_ci #endif /*@ indent of preproc. directive off by 1 (must be 0) */ 54e1051a39Sopenharmony_ci#define X (1 + 1) /*@0 extra space in body, reported unless sloppy-spc */ 55e1051a39Sopenharmony_ci#define Y 1 /*@ extra space before body, reported unless sloppy-spc */ \ 56e1051a39Sopenharmony_ci#define Z /*@2 preprocessor directive within multi-line directive */ 57e1051a39Sopenharmony_citypedef struct { /*@0 extra space in code, reported unless sloppy-spc */ 58e1051a39Sopenharmony_ci enum { /*@1 extra space in intra-line comment, no more reported */ 59e1051a39Sopenharmony_ci w = 0 /*@ hanging expr indent off by 1, or 3 for lines after '{' */ 60e1051a39Sopenharmony_ci && 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */ 61e1051a39Sopenharmony_ci x = 1, /*@ hanging expr indent off by -1 */ 62e1051a39Sopenharmony_ci y,z /*@ no space after ',', reported unless sloppy-spc */ 63e1051a39Sopenharmony_ci } e_member ; /*@ space before ';', reported unless sloppy-spc */ 64e1051a39Sopenharmony_ci int v[1; /*@ unclosed bracket in type declaration */ 65e1051a39Sopenharmony_ci union { /*@ statement/type declaration indent off by -1 */ 66e1051a39Sopenharmony_ci struct{} s; /*@ no space before '{', reported unless sloppy-spc */ 67e1051a39Sopenharmony_ci }u_member; /*@ no space after '}', reported unless sloppy-spc */ 68e1051a39Sopenharmony_ci } s_type; /*@ statement/type declaration indent off by 4 */ 69e1051a39Sopenharmony_ciint* somefunc(); /*@ no space before '*' in type decl, r unless sloppy-spc */ 70e1051a39Sopenharmony_civoid main(int n) { /*@ opening brace at end of function definition header */ 71e1051a39Sopenharmony_ci for (; ; ) ; /*@ space before ')', reported unless sloppy-spc */ 72e1051a39Sopenharmony_ci for ( ; x; y) ; /*@2 space after '(' and before ';', unless sloppy-spc */ 73e1051a39Sopenharmony_ci for (;;n++) { /*@ missing space after ';', reported unless sloppy-spc */ 74e1051a39Sopenharmony_ci return; /*@0 (1-line) single statement in braces */ 75e1051a39Sopenharmony_ci }} /*@2 code after '}' outside expr */ 76e1051a39Sopenharmony_ci} /*@ unexpected closing brace (too many '}') outside expr */ 77e1051a39Sopenharmony_ci) /*@ unexpected closing paren outside expr */ 78e1051a39Sopenharmony_ci#endif /*@ unexpected #endif */ 79e1051a39Sopenharmony_ciint f (int a, /*@ space after fn before '(', reported unless sloppy-spc */ 80e1051a39Sopenharmony_ci int b, /*@ hanging expr indent off by -1 */ 81e1051a39Sopenharmony_ci long I) /*@ single-letter name 'I' */ 82e1051a39Sopenharmony_ci{ int x; /*@ code after '{' opening a block */ 83e1051a39Sopenharmony_ci int xx = 1) + /*@ unexpected closing parenthesis */ 84e1051a39Sopenharmony_ci 0L < /*@ constant on LHS of comparison operator */ 85e1051a39Sopenharmony_ci a] - /*@ unexpected closing bracket */ 86e1051a39Sopenharmony_ci 3: * /*@ unexpected ':' (without preceding '?') within expr */ 87e1051a39Sopenharmony_ci 4}; /*@ unexpected closing brace within expression */ 88e1051a39Sopenharmony_ci char y[] = { /*@0 unclosed brace within initializer/enum expression */ 89e1051a39Sopenharmony_ci 1* 1, /*@ no space etc. before '*', reported unless sloppy-spc */ 90e1051a39Sopenharmony_ci 2, /*@ hanging expr indent (for lines after '{') off by 1 */ 91e1051a39Sopenharmony_ci (xx /*@0 unclosed parenthesis in expression */ 92e1051a39Sopenharmony_ci ? y /*@0 unclosed '? (conditional expression) */ 93e1051a39Sopenharmony_ci [0; /*@4 unclosed bracket in expression */ 94e1051a39Sopenharmony_ci /*@ blank line within local decls */ 95e1051a39Sopenharmony_ci s_type s; /*@2 local variable declaration indent off by -1 */ 96e1051a39Sopenharmony_ci t_type t; /*@ local variable declaration indent again off by -1 */ 97e1051a39Sopenharmony_ci /* */ /*@0 missing blank line after local decls */ 98e1051a39Sopenharmony_ci somefunc(a, /*@2 statement indent off by -1 */ 99e1051a39Sopenharmony_ci "aligned" /*@ expr indent off by -2 accepted if sloppy-hang */ "right" 100e1051a39Sopenharmony_ci , b, /*@ expr indent off by -1 */ 101e1051a39Sopenharmony_ci b, /*@ expr indent as on line above, accepted if sloppy-hang */ 102e1051a39Sopenharmony_ci b, /*@ expr indent off -8 but @ extra indent accepted if sloppy-hang */ 103e1051a39Sopenharmony_ci "again aligned" /*@ expr indent off by -9 (left of stmt indent, */ "right", 104e1051a39Sopenharmony_ci abc == /*@ .. so reported also with sloppy-hang; this line is too long */ 456 105e1051a39Sopenharmony_ci# define MAC(A) (A) /*@ nesting indent of preprocessor directive off by 1 */ 106e1051a39Sopenharmony_ci ? 1 /*@ hanging expr indent off by 1 */ 107e1051a39Sopenharmony_ci : 2); /*@ hanging expr indent off by 2, or 1 for leading ':' */ 108e1051a39Sopenharmony_ci if(a /*@ missing space after 'if', reported unless sloppy-spc */ 109e1051a39Sopenharmony_ci /*@0 intra-line comment indent off by -1 (not: by 3 due to '&&') */ 110e1051a39Sopenharmony_ci && ! 0 /*@2 space after '!', reported unless sloppy-spc */ 111e1051a39Sopenharmony_ci || b == /*@ hanging expr indent off by 2, or -2 for leading '||' */ 112e1051a39Sopenharmony_ci (x<<= 1) + /*@ missing space before '<<=' reported unless sloppy-spc */ 113e1051a39Sopenharmony_ci (xx+= 2) + /*@ missing space before '+=', reported unless sloppy-spc */ 114e1051a39Sopenharmony_ci (a^ 1) + /*@ missing space before '^', reported unless sloppy-spc */ 115e1051a39Sopenharmony_ci (y *=z) + /*@ missing space after '*=' reported unless sloppy-spc */ 116e1051a39Sopenharmony_ci a %2 / /*@ missing space after '%', reported unless sloppy-spc */ 117e1051a39Sopenharmony_ci 1 +/* */ /*@ no space before comment, reported unless sloppy-spc */ 118e1051a39Sopenharmony_ci /* */+ /*@ no space after comment, reported unless sloppy-spc */ 119e1051a39Sopenharmony_ci s. e_member) /*@ space after '.', reported unless sloppy-spc */ 120e1051a39Sopenharmony_ci xx = a + b /*@ extra single-statement indent off by 1 */ 121e1051a39Sopenharmony_ci + 0; /*@ two times extra single-statement indent off by 3 */ 122e1051a39Sopenharmony_ci if (a ++) /*@ space before postfix '++', reported unless sloppy-spc */ 123e1051a39Sopenharmony_ci { /*@ {' not on same line as preceding 'if' */ 124e1051a39Sopenharmony_ci c; /*@0 single stmt in braces, reported on 1-stmt */ 125e1051a39Sopenharmony_ci } else /*@ missing '{' on same line after '} else' */ 126e1051a39Sopenharmony_ci { /*@ statement indent off by 2 */ 127e1051a39Sopenharmony_ci d; /*@0 single stmt in braces, reported on 1-stmt */ 128e1051a39Sopenharmony_ci } /*@ statement indent off by 6 */ 129e1051a39Sopenharmony_ci if (1) f(a, /*@ (non-brace) code after end of 'if' condition */ 130e1051a39Sopenharmony_ci b); else /*@ (non-brace) code before 'else' */ 131e1051a39Sopenharmony_ci do f(c, c); /*@ (non-brace) code after 'do' */ 132e1051a39Sopenharmony_ci while ( 2); /*@ space after '(', reported unless sloppy-spc */ 133e1051a39Sopenharmony_ci b; c; /*@ more than one statement per line */ 134e1051a39Sopenharmony_ci outer: /*@ outer label special indent off by 1 */ 135e1051a39Sopenharmony_ci do{ /*@ missing space before '{', reported unless sloppy-spc */ 136e1051a39Sopenharmony_ci inner: /*@ inner label normal indent off by 1 */ 137e1051a39Sopenharmony_ci f (3, /*@ space after fn before '(', reported unless sloppy-spc */ 138e1051a39Sopenharmony_ci 4); /*@0 false negative: should report single stmt in braces */ 139e1051a39Sopenharmony_ci } /*@0 'while' not on same line as preceding '}' */ 140e1051a39Sopenharmony_ci while (a+ 0); /*@2 missing space before '+', reported unless sloppy-spc */ 141e1051a39Sopenharmony_ci switch (b ) { /*@ space before ')', reported unless sloppy-spc */ 142e1051a39Sopenharmony_ci case 1: /*@ 'case' special statement indent off by -1 */ 143e1051a39Sopenharmony_ci case(2): /*@ missing space after 'case', reported unless sloppy-spc */ 144e1051a39Sopenharmony_ci default: ; /*@ code after 'default:' */ 145e1051a39Sopenharmony_ci} /*@ statement indent off by -4 */ 146e1051a39Sopenharmony_ci return( /*@ missing space after 'return', reported unless sloppy-spc */ 147e1051a39Sopenharmony_ci x); } /*@ code before block-level '}' */ 148e1051a39Sopenharmony_ci/* Here the tool should stop complaining apart from the below issues at EOF */ 149e1051a39Sopenharmony_ci 150e1051a39Sopenharmony_civoid f_looong_body() 151e1051a39Sopenharmony_ci{ 152e1051a39Sopenharmony_ci ; 153e1051a39Sopenharmony_ci ; 154e1051a39Sopenharmony_ci ; 155e1051a39Sopenharmony_ci ; 156e1051a39Sopenharmony_ci ; 157e1051a39Sopenharmony_ci ; 158e1051a39Sopenharmony_ci ; 159e1051a39Sopenharmony_ci ; 160e1051a39Sopenharmony_ci ; 161e1051a39Sopenharmony_ci ; 162e1051a39Sopenharmony_ci ; 163e1051a39Sopenharmony_ci ; 164e1051a39Sopenharmony_ci ; 165e1051a39Sopenharmony_ci ; 166e1051a39Sopenharmony_ci ; 167e1051a39Sopenharmony_ci ; 168e1051a39Sopenharmony_ci ; 169e1051a39Sopenharmony_ci ; 170e1051a39Sopenharmony_ci ; 171e1051a39Sopenharmony_ci ; 172e1051a39Sopenharmony_ci ; 173e1051a39Sopenharmony_ci ; 174e1051a39Sopenharmony_ci ; 175e1051a39Sopenharmony_ci ; 176e1051a39Sopenharmony_ci ; 177e1051a39Sopenharmony_ci ; 178e1051a39Sopenharmony_ci ; 179e1051a39Sopenharmony_ci ; 180e1051a39Sopenharmony_ci ; 181e1051a39Sopenharmony_ci ; 182e1051a39Sopenharmony_ci ; 183e1051a39Sopenharmony_ci ; 184e1051a39Sopenharmony_ci ; 185e1051a39Sopenharmony_ci ; 186e1051a39Sopenharmony_ci ; 187e1051a39Sopenharmony_ci ; 188e1051a39Sopenharmony_ci ; 189e1051a39Sopenharmony_ci ; 190e1051a39Sopenharmony_ci ; 191e1051a39Sopenharmony_ci ; 192e1051a39Sopenharmony_ci ; 193e1051a39Sopenharmony_ci ; 194e1051a39Sopenharmony_ci ; 195e1051a39Sopenharmony_ci ; 196e1051a39Sopenharmony_ci ; 197e1051a39Sopenharmony_ci ; 198e1051a39Sopenharmony_ci ; 199e1051a39Sopenharmony_ci ; 200e1051a39Sopenharmony_ci ; 201e1051a39Sopenharmony_ci ; 202e1051a39Sopenharmony_ci ; 203e1051a39Sopenharmony_ci ; 204e1051a39Sopenharmony_ci ; 205e1051a39Sopenharmony_ci ; 206e1051a39Sopenharmony_ci ; 207e1051a39Sopenharmony_ci ; 208e1051a39Sopenharmony_ci ; 209e1051a39Sopenharmony_ci ; 210e1051a39Sopenharmony_ci ; 211e1051a39Sopenharmony_ci ; 212e1051a39Sopenharmony_ci ; 213e1051a39Sopenharmony_ci ; 214e1051a39Sopenharmony_ci ; 215e1051a39Sopenharmony_ci ; 216e1051a39Sopenharmony_ci ; 217e1051a39Sopenharmony_ci ; 218e1051a39Sopenharmony_ci ; 219e1051a39Sopenharmony_ci ; 220e1051a39Sopenharmony_ci ; 221e1051a39Sopenharmony_ci ; 222e1051a39Sopenharmony_ci ; 223e1051a39Sopenharmony_ci ; 224e1051a39Sopenharmony_ci ; 225e1051a39Sopenharmony_ci ; 226e1051a39Sopenharmony_ci ; 227e1051a39Sopenharmony_ci ; 228e1051a39Sopenharmony_ci ; 229e1051a39Sopenharmony_ci ; 230e1051a39Sopenharmony_ci ; 231e1051a39Sopenharmony_ci ; 232e1051a39Sopenharmony_ci ; 233e1051a39Sopenharmony_ci ; 234e1051a39Sopenharmony_ci ; 235e1051a39Sopenharmony_ci ; 236e1051a39Sopenharmony_ci ; 237e1051a39Sopenharmony_ci ; 238e1051a39Sopenharmony_ci ; 239e1051a39Sopenharmony_ci ; 240e1051a39Sopenharmony_ci ; 241e1051a39Sopenharmony_ci ; 242e1051a39Sopenharmony_ci ; 243e1051a39Sopenharmony_ci ; 244e1051a39Sopenharmony_ci ; 245e1051a39Sopenharmony_ci ; 246e1051a39Sopenharmony_ci ; 247e1051a39Sopenharmony_ci ; 248e1051a39Sopenharmony_ci ; 249e1051a39Sopenharmony_ci ; 250e1051a39Sopenharmony_ci ; 251e1051a39Sopenharmony_ci ; 252e1051a39Sopenharmony_ci ; 253e1051a39Sopenharmony_ci ; 254e1051a39Sopenharmony_ci ; 255e1051a39Sopenharmony_ci ; 256e1051a39Sopenharmony_ci ; 257e1051a39Sopenharmony_ci ; 258e1051a39Sopenharmony_ci ; 259e1051a39Sopenharmony_ci ; 260e1051a39Sopenharmony_ci ; 261e1051a39Sopenharmony_ci ; 262e1051a39Sopenharmony_ci ; 263e1051a39Sopenharmony_ci ; 264e1051a39Sopenharmony_ci ; 265e1051a39Sopenharmony_ci ; 266e1051a39Sopenharmony_ci ; 267e1051a39Sopenharmony_ci ; 268e1051a39Sopenharmony_ci ; 269e1051a39Sopenharmony_ci ; 270e1051a39Sopenharmony_ci ; 271e1051a39Sopenharmony_ci ; 272e1051a39Sopenharmony_ci ; 273e1051a39Sopenharmony_ci ; 274e1051a39Sopenharmony_ci ; 275e1051a39Sopenharmony_ci ; 276e1051a39Sopenharmony_ci ; 277e1051a39Sopenharmony_ci ; 278e1051a39Sopenharmony_ci ; 279e1051a39Sopenharmony_ci ; 280e1051a39Sopenharmony_ci ; 281e1051a39Sopenharmony_ci ; 282e1051a39Sopenharmony_ci ; 283e1051a39Sopenharmony_ci ; 284e1051a39Sopenharmony_ci ; 285e1051a39Sopenharmony_ci ; 286e1051a39Sopenharmony_ci ; 287e1051a39Sopenharmony_ci ; 288e1051a39Sopenharmony_ci ; 289e1051a39Sopenharmony_ci ; 290e1051a39Sopenharmony_ci ; 291e1051a39Sopenharmony_ci ; 292e1051a39Sopenharmony_ci ; 293e1051a39Sopenharmony_ci ; 294e1051a39Sopenharmony_ci ; 295e1051a39Sopenharmony_ci ; 296e1051a39Sopenharmony_ci ; 297e1051a39Sopenharmony_ci ; 298e1051a39Sopenharmony_ci ; 299e1051a39Sopenharmony_ci ; 300e1051a39Sopenharmony_ci ; 301e1051a39Sopenharmony_ci ; 302e1051a39Sopenharmony_ci ; 303e1051a39Sopenharmony_ci ; 304e1051a39Sopenharmony_ci ; 305e1051a39Sopenharmony_ci ; 306e1051a39Sopenharmony_ci ; 307e1051a39Sopenharmony_ci ; 308e1051a39Sopenharmony_ci ; 309e1051a39Sopenharmony_ci ; 310e1051a39Sopenharmony_ci ; 311e1051a39Sopenharmony_ci ; 312e1051a39Sopenharmony_ci ; 313e1051a39Sopenharmony_ci ; 314e1051a39Sopenharmony_ci ; 315e1051a39Sopenharmony_ci ; 316e1051a39Sopenharmony_ci ; 317e1051a39Sopenharmony_ci ; 318e1051a39Sopenharmony_ci ; 319e1051a39Sopenharmony_ci ; 320e1051a39Sopenharmony_ci ; 321e1051a39Sopenharmony_ci ; 322e1051a39Sopenharmony_ci ; 323e1051a39Sopenharmony_ci ; 324e1051a39Sopenharmony_ci ; 325e1051a39Sopenharmony_ci ; 326e1051a39Sopenharmony_ci ; 327e1051a39Sopenharmony_ci ; 328e1051a39Sopenharmony_ci ; 329e1051a39Sopenharmony_ci ; 330e1051a39Sopenharmony_ci ; 331e1051a39Sopenharmony_ci ; 332e1051a39Sopenharmony_ci ; 333e1051a39Sopenharmony_ci ; 334e1051a39Sopenharmony_ci ; 335e1051a39Sopenharmony_ci ; 336e1051a39Sopenharmony_ci ; 337e1051a39Sopenharmony_ci ; 338e1051a39Sopenharmony_ci ; 339e1051a39Sopenharmony_ci ; 340e1051a39Sopenharmony_ci ; 341e1051a39Sopenharmony_ci ; 342e1051a39Sopenharmony_ci ; 343e1051a39Sopenharmony_ci ; 344e1051a39Sopenharmony_ci ; 345e1051a39Sopenharmony_ci ; 346e1051a39Sopenharmony_ci ; 347e1051a39Sopenharmony_ci ; 348e1051a39Sopenharmony_ci ; 349e1051a39Sopenharmony_ci ; 350e1051a39Sopenharmony_ci 351e1051a39Sopenharmony_ci 352e1051a39Sopenharmony_ci ; /*@ 2 essentially blank lines before, if !sloppy-spc */ 353e1051a39Sopenharmony_ci} /*@ function body length > 200 lines */ 354e1051a39Sopenharmony_ci#if X /*@0 unclosed #if */ 355e1051a39Sopenharmony_cistruct t { /*@0 unclosed brace at decl/block level */ 356e1051a39Sopenharmony_ci enum { /*@0 unclosed brace at enum/expression level */ 357e1051a39Sopenharmony_ci v = (1 /*@0 unclosed parenthesis */ 358e1051a39Sopenharmony_ci etyp /*@0 blank line follows just before EOF, if !sloppy-spc: */ 359 360