]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
check-format.pl: allow block for switch case/default
authorDr. David von Oheimb <dev@ddvo.net>
Mon, 9 Jun 2025 11:15:58 +0000 (13:15 +0200)
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>
Mon, 16 Jun 2025 15:03:47 +0000 (17:03 +0200)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27836)

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

index f6b1bfb31920ff12306ac0e34c061d53da030814..1acea954cfdf4908488e6f8ef79aa109fbbcdabb 100644 (file)
@@ -236,6 +236,9 @@ int g(void)
                     return 0;
             }
             break;
+        case 1: {
+            ;
+        }
         default:
             /* This should be dead code */
             return 0;
index 52981753d990074d7ec933a0616a7807559c9fef..82d0b16b77a283edb39ef13023a93330fe6594df 100755 (executable)
@@ -465,7 +465,9 @@ sub update_nested_indents { # may reset $in_paren_expr and in this case also res
                 push @nested_block_indents, $block_indent;
                 push @nested_hanging_offsets, $in_expr ? $hanging_offset : 0;
                 push @nested_in_typedecl, $in_typedecl if $in_typedecl != 0;
-                $block_indent += INDENT_LEVEL + $hanging_offset;
+                my $indent_inc = INDENT_LEVEL;
+                $indent_inc = 0 if (m/^[\s@]*(case|default)\W.*\{[\s@]*$/);  # leading 'case' or 'default' and trailing '{'
+                $block_indent += $indent_inc + $hanging_offset;
                 $hanging_offset = 0;
             }
             if ($c ne "{" || $in_stmt) { # for '{' inside stmt/expr (not: decl), for '(', '[', or '?' anywhere
@@ -911,8 +913,9 @@ while (<>) { # loop over all lines of all input files
         }
 
         if (m/^[\s@]*(case|default)(\W.*$|$)/) { # leading 'case' or 'default'
-            my $keyword = $1;
-            report("code after $keyword: ") if $2 =~ /:.*[^\s@].*$/;
+            my ($keyword, $rest) = ($1, $2);
+            report("code after $keyword: ") if $rest =~ /:.*[^\s@]/ && !
+                ($rest =~ /:[\s@]*\{[\s@]*$/); # after, ':', trailing '{';
             $local_offset = -INDENT_LEVEL;
         } else {
             if (m/^([\s@]*)(\w+):/) { # (leading) label, cannot be "default"