Skip to content

Commit

Permalink
check-format.pl: extend checking into macro bodies; small further imp…
Browse files Browse the repository at this point in the history
…rovements

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from #18812)

(cherry picked from commit 1fb20f1)
  • Loading branch information
DDvO committed Mar 14, 2023
1 parent 47b0e63 commit b5e7dd3
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 63 deletions.
51 changes: 50 additions & 1 deletion util/check-format-test-negatives.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* There are some known false positives, though, which are marked below.
*/

#include <errno.h> /* should not report whitespace nits within <...> */
#define F \
void f() \
{ \
Expand All @@ -22,8 +23,12 @@
return; \
}

/* allow extra SPC in single-line comment */
/*
* allow extra SPC in regular multi-line comment
*/
/*-
* allow extra SPC in format-tagged multi-line comment
* allow extra SPC in format-tagged multi-line comment
*/
int f(void) /*
* trailing multi-line comment
Expand Down Expand Up @@ -236,6 +241,9 @@ int g(void)
&& expr_line3)
hanging_stmt;
}
#define m \
do { /* should not be confused with function header followed by '{' */ \
} while (0)

/* should not trigger: constant on LHS of comparison or assignment operator */
X509 *x509 = NULL;
Expand Down Expand Up @@ -269,6 +277,47 @@ typedef OSSL_CMP_MSG *(*cmp_srv_process_cb_t)
(OSSL_CMP_SRV_CTX *ctx, OSSL_CMP_MSG *msg)
xx;

#define IF(cond) if (cond)

_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic pop")

#define CB_ERR_IF(cond, ctx, cert, depth, err) \
if ((cond) && ((depth) < 0 || verify_cb_cert(ctx, cert, depth, err) == 0)) \
return err
static int verify_cb_crl(X509_STORE_CTX *ctx, int err)
{
ctx->error = err;
return ctx->verify_cb(0, ctx);
}

#ifdef CMP_FALLBACK_EST
# define CMP_FALLBACK_CERT_FILE "cert.pem"
#endif

#define X509_OBJECT_get0_X509(obj) \
((obj) == NULL || (obj)->type != X509_LU_X509 ? NULL : (obj)->data.x509)
#define X509_STORE_CTX_set_current_cert(ctx, x) { (ctx)->current_cert = (x); }
#define X509_STORE_set_ex_data(ctx, idx, data) \
CRYPTO_set_ex_data(&(ctx)->ex_data, (idx), (data))

typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx);
#define X509_STORE_CTX_set_error_depth(ctx, depth) \
{ (ctx)->error_depth = (depth); }
#define EVP_PKEY_up_ref(x) ((x)->references++)
/* should not report missing blank line: */
DECLARE_STACK_OF(OPENSSL_CSTRING)
bool UTIL_iterate_dir(int (*fn)(const char *file, void *arg), void *arg,
const char *path, bool recursive);
size_t UTIL_url_encode(
size_t *size_needed
);
size_t UTIL_url_encode(const char *source,
char *destination,
size_t destination_len,
size_t *size_needed);
#error well. oops.

int f()
{
c;
Expand Down
8 changes: 5 additions & 3 deletions util/check-format-test-positives.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
*/ /*@ unexpected comment ending delimiter outside comment */
/*@ comment line is 4 columns tooooooooooooooooo wide, reported unless sloppy-len */
/*@ comment line is 5 columns toooooooooooooooooooooooooooooooooooooooooooooo wide */
#define X 1 /*@0 extra space false negative due to coincidence */
#define Y 2 /*@ indent of preprocessor directive off by 1 (must be 0) */
#define X (1 + 1) /*@0 extra space in body, reported unless sloppy-spc */
#define X 1 /*@ extra space before body, reported unless sloppy-spc */
#define Y 2 /*@2 indent of preproc. directive off by 1 (must be 0) */ \
#define Z /*@ preprocessor directive within multi-line directive */
typedef struct { /*@0 extra space in code, reported unless sloppy-spc */
enum { /*@1 extra space in comment, reported unless sloppy-spc */
enum { /*@1 extra space in comment, no more reported */
w = 0 /*@ hanging expr indent off by 1, or 3 for lines after '{' */
&& 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */
x = 1, /*@ hanging expr indent off by -1 */
Expand Down

0 comments on commit b5e7dd3

Please sign in to comment.