check-format.pl: Fix report on constant on LHS of comparison/assignment
[openssl.git] / util / check-format-test-negatives.c
index d1de4104bc7869742317c34602e802e7533a0a11..8f6ed23ee72e75680e32323e654d368e71220e83 100644 (file)
@@ -1,7 +1,6 @@
 /*
- * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
- * Copyright Nokia 2007-2019
- * Copyright Siemens AG 2015-2019
+ * 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
  * There are some known false positives, though, which are marked below.
  */
 
+#define F                                       \
+    void f()                                    \
+    {                                           \
+        int i;                                  \
+        int j;                                  \
+                                                \
+        return;                                 \
+    }
+
 /*-
- * allow double space  in format-tagged multi-line comment
+ * allow extra SPC in format-tagged multi-line comment
  */
 int f(void) /*
              * trailing multi-line comment
              */
 {
-    if (ctx == NULL) { /* non-leading intra-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;
+    /*
+     * 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 */
+    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 */
@@ -150,6 +185,11 @@ int f(void) /*
         hanging_stmt;
 }
 
+/* should not trigger: constant on LHS of comparison or assignment operator */
+X509 *x509 = NULL;
+int y = a + 1 < b;
+int ret, was_NULL = *certs == NULL;
+
 const OPTIONS passwd_options[] = {
     {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"},
 #if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_DEPRECATED_3_0)
@@ -242,9 +282,9 @@ struct s_type
 
 #define X  1          + 1
 #define Y  /* .. */ 2 + 2
-#define Z  3          + 3
+#define Z  3          + 3 * (*a++)
 
-static varref cmp_vars[] = { /* comment */
+static varref cmp_vars[] = { /* comment.  comment?  comment!  */
     {&opt_config}, {&opt_section},
 
     {&opt_server}, {&opt_proxy}, {&opt_path},
@@ -269,11 +309,12 @@ static varref cmp_vars[] = { /* comment */
         /* comment */ \
     }
 
-/* 'struct' in function header */
-static int f(struct pem_pass_data *pass_data)
+union un var; /* struct/union/enum in variable type */
+struct provider_store_st *f() /* struct/union/enum in function return type */
+{
+}
+static void f(struct pem_pass_data *data) /* struct/union/enum in arg list */
 {
-    if (pass_data == NULL)
-        return 0;
 }
 
 static void *fun(void)
@@ -282,10 +323,17 @@ static void *fun(void)
         /* comment */
         return NULL;
 
+label0:
+ label1: /* allow special indent 1 for label at outermost level in body */
     do {
+    label2:
         size_t available_len, data_len;
         const char *curr = txt, *next = txt;
         char *tmp;
+
+        {
+        label3:
+        }
     } while (1);
 
     char *intraline_string_with_comment_delimiters_and_dbl_space = "1  /*1";