diff options
author | Dr. David von Oheimb <dev@ddvo.net> | 2024-07-06 17:55:25 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2024-07-08 18:45:18 +0200 |
commit | f35c0894130e34ff46a429f4373c14ca98437405 (patch) | |
tree | a8366aef0e21bca49a968067b13695cd6d72b168 | |
parent | Add (void) cast to result of ossl_quic_rxfc_on_retire() (diff) | |
download | openssl-f35c0894130e34ff46a429f4373c14ca98437405.tar.xz openssl-f35c0894130e34ff46a429f4373c14ca98437405.zip |
check_format.pl: fix detection of 'if' with single stmt in braces without 'else'
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24805)
-rw-r--r-- | util/check-format-test-negatives.c | 3 | ||||
-rwxr-xr-x | util/check-format.pl | 11 |
2 files changed, 8 insertions, 6 deletions
diff --git a/util/check-format-test-negatives.c b/util/check-format-test-negatives.c index 8b3b75db3e..3bbe0d46b6 100644 --- a/util/check-format-test-negatives.c +++ b/util/check-format-test-negatives.c @@ -335,9 +335,8 @@ size_t UTIL_url_encode(const char *source, int f() { c; - if (1) { + if (1) c; - } c; if (1) if (2) diff --git a/util/check-format.pl b/util/check-format.pl index e1a91bcc58..04dde14c9d 100755 --- a/util/check-format.pl +++ b/util/check-format.pl @@ -167,7 +167,7 @@ my $local_offset; # current extra indent due to label, switch case/defa my $line_body_start; # number of line where last function body started, or 0 my $line_function_start; # number of line where last function definition started, used for $line_body_start my $last_function_header; # header containing name of last function defined, used if $line_body_start != 0 -my $line_opening_brace; # number of previous line with opening brace after do/while/for, optionally for if/else +my $line_opening_brace; # number of previous line with opening brace after if/do/while/for, optionally for 'else' my $keyword_opening_brace; # name of previous keyword, used if $line_opening_brace != 0 my $block_indent; # currently required normal indentation at block/statement level @@ -972,9 +972,12 @@ while (<>) { # loop over all lines of all input files # check for code block containing a single line/statement if ($line_before2 > 0 && !$outermost_level && # within function body $in_typedecl == 0 && @nested_indents == 0 && # neither within type declaration nor inside stmt/expr - m/^[\s@]*\}/) { # leading closing brace '}', any preceding blinded comment must not be matched + m/^[\s@]*\}\s*(\w*)/) { # leading closing brace '}', any preceding blinded comment must not be matched # TODO extend detection from single-line to potentially multi-line statement + my $next_word = $1; if ($line_opening_brace > 0 && + ($keyword_opening_brace ne "if" || + $extended_1_stmt || $next_word ne "else") && ($line_opening_brace == $line_before2 || $line_opening_brace == $line_before) && $contents_before =~ m/;/) { # there is at least one terminator ';', so there is some stmt @@ -1132,9 +1135,9 @@ while (<>) { # loop over all lines of all input files $line_body_start = $contents =~ m/LONG BODY/ ? 0 : $line if $line_function_start != 0; } } else { - $line_opening_brace = $line if $keyword_opening_brace =~ m/do|while|for/; + $line_opening_brace = $line if $keyword_opening_brace =~ m/if|do|while|for/; # using, not assigning, $keyword_opening_brace here because it could be on an earlier line - $line_opening_brace = $line if $keyword_opening_brace =~ m/if|else/ && $extended_1_stmt && + $line_opening_brace = $line if $keyword_opening_brace eq "else" && $extended_1_stmt && # TODO prevent false positives for if/else where braces around single-statement branches # should be avoided but only if all branches have just single statements # The following helps detecting the exception when handling multiple 'if ... else' branches: |