[PATCH] checkpatch: fix unescaped left braces

From: Dwaipayan Ray
Date: Tue Jan 05 2021 - 04:36:03 EST


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.

Signed-off-by: Dwaipayan Ray <dwaipayanray1@xxxxxxxxx>
---
scripts/checkpatch.pl | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 00085308ed9d..8e80a158bf5a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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) {
--
2.27.0