Skip to content

Commit 91ec19e

Browse files
committed
check-format.pl: do checks regarding statement/block after for() also on {OSSL_,}LIST_FOREACH{,_*}
Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from openssl#25535)
1 parent 260ecea commit 91ec19e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

util/check-format.pl

+7-7
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ sub check_nested_nonblock_indents {
792792
# treat remaining blinded comments and string literal contents as (single) space during matching below
793793
$intra_line =~ s/@+/ /g; # note that extra SPC has already been handled above
794794
$intra_line =~ s/\s+$//; # strip any (resulting) space at EOL
795-
# replace ';;' or '; ;' by ';' in "for(;;)" and in "for (...)" unless "..." contains just SPC and ';' characters:
795+
# replace ';;' or '; ;' by ';' in "for (;;)" and in "for (...)" unless "..." contains just SPC and ';' characters:
796796
$intra_line =~ s/((^|\W)for\s*\()([^;]*?)(\s*)(;\s?);(\s*)([^;]*)(\))/
797797
"$1$3$4".("$3$4$5$6$7" eq ";" || $3 ne "" || $7 ne "" ? "" : $5).";$6$7$8"/eg;
798798
# strip trailing ';' or '; ' in "for (...)" except in "for (;;)" or "for (;; )":
@@ -905,7 +905,7 @@ sub check_nested_nonblock_indents {
905905
# handle opening brace '{' after if/else/while/for/switch/do on line before
906906
if ($hanging_offset > 0 && m/^[\s@]*{/ && # leading opening '{'
907907
$line_before > 0 &&
908-
$contents_before_ =~ m/(^|^.*\W)(if|else|while|for|switch|do)(\W.*$|$)/) {
908+
$contents_before_ =~ m/(^|^.*\W)(if|else|while|for|(OSSL_)?LIST_FOREACH(_\w+)?|switch|do)(\W.*$|$)/) {
909909
$keyword_opening_brace = $1;
910910
$hanging_offset -= INDENT_LEVEL; # cancel newly hanging_offset
911911
}
@@ -967,7 +967,7 @@ sub check_nested_nonblock_indents {
967967
968968
my $outermost_level = $block_indent - $preproc_offset == 0;
969969
970-
report("more than one stmt") if !m/(^|\W)for(\W.*|$)/ && # no 'for' - TODO improve matching
970+
report("more than one stmt") if !m/(^|\W)(for|(OSSL_)?LIST_FOREACH(_\w+)?)(\W.*|$)/ && # no 'for' - TODO improve matching
971971
m/;.*;/; # two or more terminators ';', so more than one statement
972972
973973
# check for code block containing a single line/statement
@@ -1005,7 +1005,7 @@ sub check_nested_nonblock_indents {
10051005
my $assignment_start = 0;
10061006
my $tmp = $_;
10071007
$tmp =~ s/[\!<>=]=/@@/g; # blind (in-)equality symbols like '<=' as '@@' to prevent matching them as '=' below
1008-
if (m/^((^|.*\W)(if|while|for|switch))(\W.*|$)$/) { # (last) if/for/while/switch
1008+
if (m/^((^|.*\W)(if|while|for|(OSSL_)?LIST_FOREACH(_\w+)?|switch))(\W.*|$)$/) { # (last) if/for/while/switch
10091009
$paren_expr_start = 1;
10101010
} elsif (m/^((^|.*\W)(return|enum))(\W.*|$)/ # (last) return/enum
10111011
&& !$in_expr && @nested_indents == 0 && parens_balance($1) == 0) { # not nested enum
@@ -1136,7 +1136,7 @@ sub check_nested_nonblock_indents {
11361136
$line_body_start = $contents =~ m/LONG BODY/ ? 0 : $line if $line_function_start != 0;
11371137
}
11381138
} else {
1139-
$line_opening_brace = $line if $keyword_opening_brace =~ m/if|do|while|for/;
1139+
$line_opening_brace = $line if $keyword_opening_brace =~ m/if|do|while|for|(OSSL_)?LIST_FOREACH(_\w+)?/;
11401140
# using, not assigning, $keyword_opening_brace here because it could be on an earlier line
11411141
$line_opening_brace = $line if $keyword_opening_brace eq "else" && $extended_1_stmt &&
11421142
# TODO prevent false positives for if/else where braces around single-statement branches
@@ -1149,11 +1149,11 @@ sub check_nested_nonblock_indents {
11491149
}
11501150
}
11511151
1152-
# check for opening brace after if/while/for/switch/do not on same line
1152+
# check for opening brace after if/while/for/switch/do missing on same line
11531153
# note that "missing '{' on same line after '} else'" is handled further below
11541154
if (/^[\s@]*{/ && # leading '{'
11551155
$line_before > 0 && !($contents_before_ =~ m/^\s*#/) && # not preprocessor directive '#if
1156-
(my ($head, $mid, $tail) = ($contents_before_ =~ m/(^|^.*\W)(if|while|for|switch|do)(\W.*$|$)/))) {
1156+
(my ($head, $mid, $tail) = ($contents_before_ =~ m/(^|^.*\W)(if|while|for|(OSSL_)?LIST_FOREACH(_\w+)?|switch|do)(\W.*$|$)/))) {
11571157
my $brace_after = $tail =~ /^[\s@]*{/; # any whitespace or comments then '{'
11581158
report("'{' not on same line as preceding '$mid'") if !$brace_after;
11591159
}

0 commit comments

Comments
 (0)