check-format.pl: Fix false positive on struct/union/enum in func return type
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Thu, 29 Apr 2021 07:41:30 +0000 (09:41 +0200)
committerDr. David von Oheimb <dev@ddvo.net>
Thu, 20 May 2021 14:29:13 +0000 (16:29 +0200)
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15077)

util/check-format-test-negatives.c
util/check-format.pl

index 89b8b19c2e33a4c6008fc42367c02dc46c2afe6b..c73cc04695b08a88c5b8bb0989b49454044b5a70 100644 (file)
@@ -273,11 +273,12 @@ static varref cmp_vars[] = { /* comment.  comment?  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)
index 734022c5403aeb81d8d29c30282b0793721c375a..882b38de41db4953d87997610b6d0ea532b5d5d6 100755 (executable)
@@ -929,10 +929,12 @@ while (<>) { # loop over all lines of all input files
     }
 
     # set $in_typedecl and potentially $hanging_offset for type declaration
-    if (!$in_expr && @nested_indents == 0 && # not in expression
-        m/(^|^.*\W)(typedef|struct|union|enum)(\W.*|$)$/ &&
-        parens_balance($1) == 0) { # not in newly started expression
-        # not needed: $keyword_opening_brace = $2 if $3 =~ m/\{/;
+    if (!$in_expr && @nested_indents == 0 # not in expression
+        && m/(^|^.*\W)(typedef|struct|union|enum)(\W.*|$)$/
+        && parens_balance($1) == 0 # not in newly started expression or function arg list
+        && ($2 eq "typedef" || !($3 =~ m/\s*\w++\s*(.)/ && $1 ne "{")) # 'struct'/'union'/'enum' <name> not followed by '{'
+        # not needed: && $keyword_opening_brace = $2 if $3 =~ m/\{/;
+        ) {
         $in_typedecl++;
         $hanging_offset += INDENT_LEVEL if m/\*.*\(/; # '*' followed by '(' - seems consistent with Emacs C mode
     }