checkpatch: fix unescaped left braces
PATCH 1/1 checkpatch: fix unescaped left braces
Perl 5.22 onwards require that "A literal "{" should now be escaped in a pattern".
checkpatch contains several literal "{". Fix such instances by preceding them with a backslash.
--- scripts/checkpatch.pl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
scripts/checkpatch.pl +14 -14
@@ -1652,7 +1652,7 @@ sub statement_block_size { my ($stmt) = @_; $stmt =~ s/(^|\n)./$1/g; - $stmt =~ s/^\s*{//; + $stmt =~ s/^\s*\{//; $stmt =~ s/}\s*$//; $stmt =~ s/^\s*//; $stmt =~ s/\s*$//;
@@ -2036,7 +2036,7 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N'; - } elsif ($cur =~/^(;|{|})/) { + } elsif ($cur =~ /^(;|\{|\})/) { print "END($1)\n" if ($dbg_values > 1); $type = 'E'; $av_pend_colon = 'O';
@@ -3913,7 +3913,7 @@ sub process { # it there is no point in retrying a statement scan # until we hit end of it. my $frag = $stat; $frag =~ s/;+\s*$//; - if ($frag !~ /(?:{|;)/) { + if ($frag !~ /(?:\{|;)/) { #print "skip<$line_nr_next>\n"; $suppress_statement = $line_nr_next; }
@@ -4029,7 +4029,7 @@ sub process { #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n"; #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; - if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { + if ($ctx !~ /\{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*\{/) { ERROR("OPEN_BRACE", "that open brace { should be on the previous line\n" . "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
@@ -4080,7 +4080,7 @@ sub process { my $continuation = 0; my $check = 0; $s =~ s/^.*\bdo\b//; - $s =~ s/^\s*{//; + $s =~ s/^\s*\{//; if ($s =~ s/^\s*\\//) { $continuation = 1; }
@@ -4235,7 +4235,7 @@ sub process { } # check for initialisation to aggregates open brace on the next line - if ($line =~ /^.\s*{/ && + if ($line =~ /^.\s*\{/ && $prevline =~ /(?:^|[^=])=\s*$/) { if (ERROR("OPEN_BRACE", "that open brace { should be on the previous line\n" . $hereprev) &&
@@ -4243,7 +4243,7 @@ sub process { fix_delete_line($fixlinenr - 1, $prevrawline); fix_delete_line($fixlinenr, $rawline); my $fixedline = $prevrawline; - $fixedline =~ s/\s*=\s*$/ = {/; + $fixedline =~ s/\s*=\s*$/ = \{/; fix_insert_line($fixlinenr, $fixedline); $fixedline = $line; $fixedline =~ s/^(.\s*)\{\s*/$1/;
@@ -4617,7 +4617,7 @@ sub process { } # open braces for enum, union and struct go on the same line. - if ($line =~ /^.\s*{/ && + if ($line =~ /^.\s*\{/ && $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { if (ERROR("OPEN_BRACE", "open brace '{' following $1 go on the same line\n" . $hereprev) &&
@@ -5345,7 +5345,7 @@ sub process { # Check for illegal assignment in if conditional -- and check for trailing # statements after the conditional. - if ($line =~ /do\s*(?!{)/) { + if ($line =~ /do\s*(?!\{)/) { ($stat, $cond, $line_nr_next, $remain_next, $off_next) = ctx_statement_block($linenr, $realcnt, 0) if (!defined $stat);
@@ -5403,7 +5403,7 @@ sub process { substr($s, 0, length($c), ''); $s =~ s/\n.*//g; $s =~ s/$;//g; # Remove any comments - if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ && + if (length($c) && $s !~ /^\s*\{?\s*\\*\s*$/ && $c !~ /}\s*while\s*/) { # Find out how long the conditional actually is.
@@ -5442,7 +5442,7 @@ sub process { if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { my $s = $1; $s =~ s/$;//g; # Remove any comments - if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { + if ($s !~ /^\s*(?:\sif|(?:\{|)\s*\\?\s*$)/) { ERROR("TRAILING_STATEMENTS", "trailing statements should be on next line\n" . $herecurr); }
@@ -5659,7 +5659,7 @@ sub process { $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...} $dstat !~ /^for\s*$Constant$/ && # for (...) $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar() - $dstat !~ /^do\s*{/ && # do {... + $dstat !~ /^do\s*\{/ && # do {... $dstat !~ /^\(\{/ && # ({... $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) {
@@ -5811,7 +5811,7 @@ sub process { substr($block, 0, length($cond), ''); - $seen++ if ($block =~ /^\s*{/); + $seen++ if ($block =~ /^\s*\{/); #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n"; if (statement_lines($cond) > 1) {
@@ -5909,7 +5909,7 @@ sub process { fix_delete_line($fixlinenr - 1, $prevrawline); } } - if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) { + if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*\{\s*$/)) { if (CHK("BRACES", "Blank lines aren't necessary after an open brace '{'\n" . $hereprev) && $fix) {
Signature · 6 lines
2.27.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Joe Perches
maintainerQuoted 2 lines · Dwaipayan Ray
Perl 5.22 onwards require that "A literal "{" should now be escaped in a pattern".
Not quite correct.
Quoted 2 lines
checkpatch contains several literal "{". Fix such instances by preceding them with a backslash.
Not all literal left braces need to be escaped.
https://www.perlmonks.org/?node_id=1191981
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
scripts/checkpatch.pl sub annotate_values { · line 2039
Quoted 7 lines
scripts/checkpatch.pl +0
-0@@ -2036,7 +2036,7 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N';scripts/checkpatch.pl +1
-1- } elsif ($cur =~/^(;|{|})/) { + } elsif ($cur =~ /^(;|\{|\})/) {
Like this one. And why escape the right brace too?
scripts/checkpatch.pl sub process { · line 3916
Quoted 9 lines
print "END($1)\n" if ($dbg_values > 1); $type = 'E';
$av_pend_colon = 'O';scripts/checkpatch.pl +1
-1@@ -3913,7 +3913,7 @@ sub process { # it there is no point in retrying a statement scan # until we hit end of it. my $frag = $stat; $frag =~ s/;+\s*$//; - if ($frag !~ /(?:{|;)/) { + if ($frag !~ /(?:\{|;)/) {
And here.
etc...
Quoted 5 lines · Joe Perches
Quoted 2 lines · Dwaipayan Ray
Perl 5.22 onwards require that "A literal "{" should now be escaped in a pattern".
Quoted 8 lines
Not quite correct.
Quoted 2 lines
checkpatch contains several literal "{". Fix such instances by preceding them with a backslash.
Not all literal left braces need to be escaped.
https://www.perlmonks.org/?node_id=1191981
Thanks, I got this from perl diag:
"
The contexts where no warnings or errors are raised are:
as the first character in a pattern, or following "^" indicating to anchor the match to the beginning of a line.
as the first character following a "|" indicating alternation. as the first character in a parenthesized grouping like /foo({bar)/
/foo(?:{bar)/
as the first character following a quantifier
/\s*{/
"
I will update the patch with the above in mind.
Quoted 7 lines
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 5 lines
scripts/checkpatch.pl +0
-0@@ -2036,7 +2036,7 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N';
Quoted 5 lines
scripts/checkpatch.pl sub annotate_values { · line 2039
Quoted 2 lines
scripts/checkpatch.pl +1
-1- } elsif ($cur =~/^(;|{|})/) { + } elsif ($cur =~ /^(;|\{|\})/) {Like this one. And why escape the right brace too?
The right brace escape was just for the expression to look a bit even. It's unneeded, will remove these too.
Quoted 12 lines
scripts/checkpatch.pl sub process { · line 3916
Quoted 9 lines
scripts/checkpatch.pl +0
-0print "END($1)\n" if ($dbg_values > 1); $type = 'E';$av_pend_colon = 'O';scripts/checkpatch.pl +1
-1@@ -3913,7 +3913,7 @@ sub process { # it there is no point in retrying a statement scan # until we hit end of it. my $frag = $stat; $frag =~ s/;+\s*$//; - if ($frag !~ /(?:{|;)/) { + if ($frag !~ /(?:\{|;)/) {And here.
Quoted 2 lines
etc...
Thank you,
Dwaipayan.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
From: Joe Perches
Quoted 5 lines
Sent: 05 January 2021 10:01
Quoted 2 lines · Dwaipayan Ray
Perl 5.22 onwards require that "A literal "{" should now be escaped in a pattern".
Sounds like a good reason to never use perl :-)
Quoted 10 lines
Not quite correct.
Quoted 2 lines
checkpatch contains several literal "{". Fix such instances by preceding them with a backslash.
Not all literal left braces need to be escaped.
https://www.perlmonks.org/?node_id=1191981scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 7 lines
scripts/checkpatch.pl sub annotate_values { · line 2040
Quoted 7 lines
scripts/checkpatch.pl +1
-1@@ -2036,7 +2036,7 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N'; - } elsif ($cur =~/^(;|{|})/) { + } elsif ($cur =~ /^(;|\{|\})/) {
isn't (;|{|}) much the same as [;{}] ??
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Joe Perches
maintainerQuoted 24 lines · David Laight
From: Joe Perches
Quoted 5 lines
Sent: 05 January 2021 10:01
Quoted 2 lines · Dwaipayan Ray
Perl 5.22 onwards require that "A literal "{" should now be escaped in a pattern".
Sounds like a good reason to never use perl :-)
Quoted 15 lines
Not quite correct.
Quoted 2 lines
checkpatch contains several literal "{". Fix such instances by preceding them with a backslash.
Not all literal left braces need to be escaped.
https://www.perlmonks.org/?node_id=1191981scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 5 lines
scripts/checkpatch.pl +0
-0@@ -2036,7 +2036,7 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N';
Quoted 4 lines
Quoted 2 lines
scripts/checkpatch.pl sub annotate_values { · line 2039
Quoted 2 lines
scripts/checkpatch.pl +1
-1- } elsif ($cur =~/^(;|{|})/) { + } elsif ($cur =~ /^(;|\{|\})/) {isn't (;|{|}) much the same as [;{}] ??
Yes, but without the capture, so /^([;{}])/ would be the same.
I presume the | style was used for consistency with other uses in the same block.
Andy Whitcroft wrote that bit a long time ago.