From: Dr. David von Oheimb Date: Mon, 9 Jun 2025 11:15:58 +0000 (+0200) Subject: check-format.pl: allow block for switch case/default X-Git-Tag: openssl-3.5.1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa47158382b426d2b5ef343693f9391a761d274b;p=thirdparty%2Fopenssl.git check-format.pl: allow block for switch case/default Reviewed-by: Neil Horman Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27836) (cherry picked from commit 560ea7ffbf5abac871a8d53f6aa3a44ac0349619) --- diff --git a/util/check-format-test-negatives.c b/util/check-format-test-negatives.c index f6b1bfb3192..1acea954cfd 100644 --- a/util/check-format-test-negatives.c +++ b/util/check-format-test-negatives.c @@ -236,6 +236,9 @@ int g(void) return 0; } break; + case 1: { + ; + } default: /* This should be dead code */ return 0; diff --git a/util/check-format.pl b/util/check-format.pl index 52981753d99..82d0b16b77a 100755 --- a/util/check-format.pl +++ b/util/check-format.pl @@ -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"