Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.kernel > #61735

Bug#905116: [PATCH] scripts/kernel-doc: Escape all literal braces in regexes

From Ben Hutchings <ben@decadent.org.uk>
Newsgroups linux.debian.bugs.dist, linux.debian.kernel
Subject Bug#905116: [PATCH] scripts/kernel-doc: Escape all literal braces in regexes
Date 2018-08-05 18:30 +0200
Message-ID <wju4O-8jl-7@gated-at.bofh.it> (permalink)
References <whAxH-3DS-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Cross-posted to 2 groups.

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Braces are usually metacharacters in regexes, used to specify a
number of repetitions or as part of an escape sequence.  If this
interpretation is not possible then Perl currently treats them
as literal characters.

Perl 5.28 has deprecated the literal interpretation of left braces,
and Perl 5.32 will remove it (resulting in a fatal error).

Escape all left braces that are treated as literal characters.  Also
escape literal right braces, for consistency and to avoid confusing
bracket-matching in text editors.

References: https://bugs.debian.org/905116
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
I tested that the output of "make xmldocs" is identical before and
after this change, whether using Perl 5.26 or 5.28.

Ben.

 scripts/kernel-doc | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 0057d8eafcc1..8f0f508a78e9 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1062,7 +1062,7 @@ sub dump_struct($$) {
     my $x = shift;
     my $file = shift;
 
-    if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
+    if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}/) {
 	my $decl_type = $1;
 	$declaration_name = $2;
 	my $members = $3;
@@ -1148,20 +1148,20 @@ sub dump_struct($$) {
 				}
 			}
 		}
-		$members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/;
+		$members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/;
 	}
 
 	# Ignore other nested elements, like enums
-	$members =~ s/({[^\{\}]*})//g;
+	$members =~ s/(\{[^\{\}]*\})//g;
 
 	create_parameterlist($members, ';', $file, $declaration_name);
 	check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
 
 	# Adjust declaration for better display
-	$declaration =~ s/([{;])/$1\n/g;
-	$declaration =~ s/}\s+;/};/g;
+	$declaration =~ s/([\{;])/$1\n/g;
+	$declaration =~ s/\}\s+;/};/g;
 	# Better handle inlined enums
-	do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/);
+	do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);
 
 	my @def_args = split /\n/, $declaration;
 	my $level = 1;
@@ -1171,12 +1171,12 @@ sub dump_struct($$) {
 		$clause =~ s/\s+$//;
 		$clause =~ s/\s+/ /;
 		next if (!$clause);
-		$level-- if ($clause =~ m/(})/ && $level > 1);
+		$level-- if ($clause =~ m/(\})/ && $level > 1);
 		if (!($clause =~ m/^\s*#/)) {
 			$declaration .= "\t" x $level;
 		}
 		$declaration .= "\t" . $clause . "\n";
-		$level++ if ($clause =~ m/({)/ && !($clause =~m/}/));
+		$level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
 	}
 	output_declaration($declaration_name,
 			   'struct',
@@ -1244,7 +1244,7 @@ sub dump_enum($$) {
     # strip #define macros inside enums
     $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
 
-    if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
+    if ($x =~ /enum\s+(\w+)\s*\{(.*)\}/) {
 	$declaration_name = $1;
 	my $members = $2;
 	my %_members;
@@ -1785,7 +1785,7 @@ sub process_proto_type($$) {
     }
 
     while (1) {
-	if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
+	if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
             if( length $prototype ) {
                 $prototype .= " "
             }

Back to linux.debian.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Bug#905116: scripts/kernel-doc: Unescaped left brace in regex is deprecated Niko Tyni <ntyni@debian.org> - 2018-07-31 13:00 +0200
  Bug#905116: [PATCH] scripts/kernel-doc: Escape all literal braces in regexes Ben Hutchings <ben@decadent.org.uk> - 2018-08-05 18:30 +0200
  Bug#905116: [PATCH v2] scripts/kernel-doc: Escape all literal braces in regexes Ben Hutchings <ben@decadent.org.uk> - 2018-08-05 18:50 +0200
    Bug#905116: [PATCH v2] scripts/kernel-doc: Escape all literal braces in regexes Jonathan Corbet <corbet@lwn.net> - 2018-08-06 15:30 +0200
      Bug#905116: [PATCH v2] scripts/kernel-doc: Escape all literal braces in regexes Ben Hutchings <ben@decadent.org.uk> - 2018-08-06 17:50 +0200
    Bug#905116: [PATCH v2] scripts/kernel-doc: Escape all literal braces in regexes Jonathan Corbet <corbet@lwn.net> - 2018-08-06 21:40 +0200
  Bug#905116: marked as done (scripts/kernel-doc: Unescaped left  brace in regex is deprecated) "Debian Bug Tracking System" <owner@bugs.debian.org> - 2018-08-28 10:20 +0200
  Bug#905116: marked as done (scripts/kernel-doc: Unescaped left  brace in regex is deprecated) "Debian Bug Tracking System" <owner@bugs.debian.org> - 2018-08-28 10:20 +0200
  Bug#905116: marked as done (scripts/kernel-doc: Unescaped left  brace in regex is deprecated) "Debian Bug Tracking System" <owner@bugs.debian.org> - 2018-08-28 17:10 +0200

csiph-web