/*
* Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
* Copyright Siemens AG 2015-2022
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* A collection of test cases where check-format.pl should not report issues.
* There are some known false positives, though, which are marked below.
*/
#define F \
void f() \
{ \
int i; \
int j; \
\
return; \
}
/*-
* allow extra SPC in format-tagged multi-line comment
*/
int f(void) /*
* trailing multi-line comment
*/
{
typedef int INT;
void v;
short b;
char c;
signed s;
unsigned u;
int i;
long l;
float f;
double d;
enum {} enu;
struct {} stru;
union {} un;
auto a;
extern e;
static int stat;
const int con;
volatile int vola;
register int reg;
OSSL_x y, *p = params;
int params[];
OSSL_PARAM * (* params []) [MAX + 1];
XY *(* fn)(int a, char b);
/*
* multi-line comment should not disturb detection of local decls
*/
BIO1 ***b;
/* intra-line comment should not disturb detection of local decls */
unsigned k;
/* intra-line comment should not disturb detection of end of local decls */
{
int x; /* just decls in block */
}
if (p != (unsigned char *)
&(ctx->tmp[0])) {
i -= (p - (unsigned char *) /* do not confuse with var decl */
&(ctx->tmp[0]));
}
{
ctx->buf_off = 0; /* do not confuse with var decl */
return 0;
}
{
ctx->buf_len = EVP_EncodeBlock((unsigned char *)ctx->buf,
(unsigned char *)ctx->tmp, /* no decl */
ctx->tmp_len);
}
{
EVP_EncodeFinal(ctx->base64,
(unsigned char *)ctx->buf, &(ctx->len)); /* no decl */
/* push out the bytes */
goto again;
}
{
f(1, (unsigned long)2); /* no decl */
x;
}
{
char *pass_str = get_passwd(opt_srv_secret, "x");
if (pass_str != NULL) {
cleanse(opt_srv_secret);
res = OSSL_CMP_CTX_set1_secretValue(ctx, (unsigned char *)pass_str,
strlen(pass_str));
clear_free(pass_str);
}
}
}
int g(void)
{
if (ctx == NULL) { /* non-leading end-of-line comment */
if (/* comment after '(' */ pem_name != NULL /* comment before ')' */)
/* entire-line comment indent usually like for the following line */
return NULL; /* hanging indent also for this line after comment */
/* leading comment has same indentation as normal code */ stmt;
/* entire-line comment may have same indent as normal code */
}
for (;;)
;
for (i = 0;;)
;
for (i = 0; i < 1;)
;
for (;;)
for (; i < n; i++)
for (;; p++)
;
for (;;) ; /* should not trigger: space before ';' */
lab: ; /* should not trigger: space before ';' */
#if X
if (1) /* bad style: just part of control structure depends on #if */
#else
if (2) /*@ resulting false positive */
#endif
c; /*@ resulting false positive */
if (1)
if (2)
c;
else
e;
else
f;
do
do
2;
while (1);
while (2);
if (1)
f(a, b);
do
1; while (2); /*@ more than one stmt just to construct case */
if (1)
f(a, b);
else
do
1;
while (2);
if (1)
f(a, b);
else do /*@ (non-brace) code before 'do' just to construct case */
1;
while (2);
f1234(a,
b); do /*@ (non-brace) code before 'do' just to construct case */
1;
while (2);
if (1)
f(a,
b); do /*@ (non-brace) code before 'do' just to construct case */
1;
while (2);
if (1)
f(a, b);
else
do f(c, c); /*@ (non-brace) code after 'do' just to construct case */
while (2);
if (1)
f(a, b);
else
return;
if (1)
f(a,
b); else /*@ (non-brace) code before 'else' just to construct case */
do
1;
while (2);
if (1)
{ /*@ brace after 'if' not on same line just to construct case */
c;
d;
}
/* this comment is correctly indented if it refers to the following line */
d;
if (1) {