diff --git a/util/check-format-test-negatives.c b/util/check-format-test-negatives.c index f6b1bfb31920ff..3b0bd6e7dd5ab4 100644 --- a/util/check-format-test-negatives.c +++ b/util/check-format-test-negatives.c @@ -268,6 +268,7 @@ float z = 1e-6 * (-1) * b[+6] * 1e+1 * (a)->f * (long)+1 - (tmstart.tv_sec + tmstart.tv_nsec * 1e-9); struct st = {-1, 0}; int x = (y <<= 1) + (z <= 5.0); +++*pnum; const OPTIONS passwd_options[] = { {"aixmd5", OPT_AIXMD5, '-', "AIX MD5-based password algorithm"}, diff --git a/util/check-format-test-positives.c b/util/check-format-test-positives.c index e5dacdfe71b92b..69479f945773ad 100644 --- a/util/check-format-test-positives.c +++ b/util/check-format-test-positives.c @@ -58,12 +58,13 @@ typedef struct { /*@0 extra space in code, reported unless sloppy-spc */ w = 0 /*@ hanging expr indent off by 1, or 3 for lines after '{' */ && 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */ x = 1, /*@ hanging expr indent off by -1 */ - y,z /*@ no space after ',', reported unless sloppy-spc */ - } e_member ; /*@ space before ';', reported unless sloppy-spc */ - int v[1; /*@ unclosed bracket in type declaration */ + y,z, /*@ missing space after ',', reported unless sloppy-spc */ + zz} /*@ code before closing brace '}' */ + e_member ; /*@ space before ';', reported unless sloppy-spc */ + int v[1; /*@ unclosed bracket '[' in variable declaration */ union { /*@ statement/type declaration indent off by -1 */ - struct{} s; /*@ no space before '{', reported unless sloppy-spc */ - }u_member; /*@ no space after '}', reported unless sloppy-spc */ + struct{} s; /*@ missing space before '{', reported unless sloppy-spc */ + }u_member; /*@ missing space after '}', reported unless sloppy-spc */ } s_type; /*@ statement/type declaration indent off by 4 */ int* somefunc(); /*@ no space before '*' in type decl, r unless sloppy-spc */ void main(int n) { /*@ opening brace at end of function definition header */ @@ -143,7 +144,7 @@ int f (int a, /*@ space after fn before '(', reported unless sloppy-spc */ default: ; /*@ code after 'default:' */ } /*@ statement indent off by -4 */ return( /*@ missing space after 'return', reported unless sloppy-spc */ - x); } /*@ code before block-level '}' */ + x); } /*@ code before '}' in stmt/expr/typedecl */ /* Here the tool should stop complaining apart from the below issues at EOF */ void f_looong_body() diff --git a/util/check-format.pl b/util/check-format.pl index 52981753d99007..2767e0aa237f2b 100755 --- a/util/check-format.pl +++ b/util/check-format.pl @@ -461,7 +461,7 @@ sub update_nested_indents { # may reset $in_paren_expr and in this case also res if ($c eq "{") { # '{' in any context $in_block_decls = 0 if !$in_expr && $in_typedecl == 0; # cancel newly hanging_offset if opening brace '{' is after non-whitespace non-comment: - $hanging_offset -= INDENT_LEVEL if $hanging_offset > 0 && $head =~ m/[^\s\@]/; + $hanging_offset -= INDENT_LEVEL if $hanging_offset > 0 && $head =~ m/[^\s@]/; 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; @@ -469,7 +469,7 @@ sub update_nested_indents { # may reset $in_paren_expr and in this case also res $hanging_offset = 0; } if ($c ne "{" || $in_stmt) { # for '{' inside stmt/expr (not: decl), for '(', '[', or '?' anywhere - $tail =~ m/^([\s@]*)([^\s\@])/; + $tail =~ m/^([\s@]*)([^\s@])/; push @nested_indents, defined $2 ? $i + 1 + length($1) # actual indentation of following non-space non-comment : $c ne "{" ? +($i + 1) # just after '(' or '[' if only whitespace thereafter @@ -512,7 +512,7 @@ sub update_nested_indents { # may reset $in_paren_expr and in this case also res check_nested_nonblock_indents("(expr)"); $in_paren_expr = $in_expr = 0; report("code after (expr)") - if $tail =~ m/^([^{]*)/ && $1 =~ m/[^\s\@;]/; # non-space non-';' before any '{' + if $tail =~ m/^([^{]*)/ && $1 =~ m/[^\s@;]/; # non-space non-';' before any '{' } } } @@ -858,8 +858,8 @@ sub check_nested_nonblock_indents { } elsif (m/^([\s@]*)(static_)?ASN1_ITEM_TEMPLATE_END(\W|$)/) { # workaround for ASN1 macro indented as '}' $local_offset = -INDENT_LEVEL; $expr_indent = 0; - } elsif (m/;.*?\}/) { # expr ends with ';' before '}' - report("code before '}'"); + } elsif (m/^([^{}]*?)\}/ && $1 =~ m/[^\s@]/) { # code before '}' not containing '{' + report("code before '}' in stmt/expr/decl"); } } if (@in_do_hanging_offsets != 0 && # note there is nothing like "unexpected 'while'" @@ -880,9 +880,9 @@ sub check_nested_nonblock_indents { } if (!$in_stmt) { # at block level, i.e., outside expr/stmt/type decl/var def/fn hdr $if_maybe_terminated = 0; - if (my ($head, $before, $tail) = m/^([\s@]*([^{}]*)\})[\s@]*(.*)$/) { # leading closing '}', but possibly - # with non-whitespace non-'{' before - report("code after '}'") unless $tail eq "" || $tail =~ m/(else|while|OSSL_TRACE_END)(\W|$)/; + if (my ($head, $before, $tail) = m/^([\s@]*([^{}]*)\})[\s@]*(.*)$/) { + # first closing '}', possibly with non-whitespace non-'{' before + report("code after '}' at block level") unless $tail eq "" || $tail =~ m/(else|while|OSSL_TRACE_END)(\W|$)/; my $outermost_level = @nested_block_indents == 1 && @nested_block_indents[0] == 0; if (!$sloppy_bodylen && $outermost_level && $line_body_start != 0) { my $body_len = $line - $line_body_start - 1; @@ -891,7 +891,7 @@ sub check_nested_nonblock_indents { $line_body_start = 0; } if ($before ne "") { # non-whitespace non-'{' before '}' - report("code before '}'"); + report("code before '}' at block level"); } else { # leading '}' outside stmt, any preceding blinded comment must not be matched $in_block_decls = -1; $local_offset = $block_indent + $hanging_offset - INDENT_LEVEL; @@ -970,6 +970,7 @@ sub check_nested_nonblock_indents { report("more than one stmt") if !m/(^|\W)(for|(OSSL_)?LIST_FOREACH(_\w+)?)(\W.*|$)/ && # no 'for' - TODO improve matching m/;.*;/; # two or more terminators ';', so more than one statement +# report("code before '}'") if m/[^\s@\}][\s@]*\}/; # closing brace '}' # 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 @@ -1036,9 +1037,9 @@ sub check_nested_nonblock_indents { # set $hanging_offset and $keyword_opening_brace for do/else if (my ($head, $mid, $tail) = m/(^|^.*\W)(else|do)(\W.*|$)$/) { # last else/do, where 'do' is preferred, but not #else - my $code_before = $head =~ m/[^\s\@}]/; # leading non-whitespace non-comment non-'}' + my $code_before = $head =~ m/[^\s@}]/; # leading non-whitespace non-comment non-'}' report("code before '$mid'") if $code_before; - report("code after '$mid'" ) if $tail =~ m/[^\s\@{]/# trailing non-whitespace non-comment non-'{' (non-'\') + report("code after '$mid'" ) if $tail =~ m/[^\s@\{]/# trailing non-whitespace non-comment non-'{' (non-'\') && !($mid eq "else" && $tail =~ m/[\s@]*if(\W|$)/); if ($mid eq "do") { # workarounds for code before 'do' if ($head =~ m/(^|^.*\W)(else)(\W.*$|$)/) { # 'else' ... 'do' @@ -1144,7 +1145,7 @@ sub check_nested_nonblock_indents { # The following helps detecting the exception when handling multiple 'if ... else' branches: !($keyword_opening_brace eq "else" && $line_opening_brace < $line_before2); } - report("code after '{'") if $tail=~ m/[^\s\@]/ && # trailing non-whitespace non-comment (non-'\') + report("code after '{'") if $tail=~ m/[^\s@]/ && # trailing non-whitespace non-comment (non-'\') !($tail=~ m/\}/); # missing '}' after last '{' } }