34484a
From dc5c68130b7c8b727e9e792506183c255fc2bc70 Mon Sep 17 00:00:00 2001
34484a
From: Tony Cook <tony@develop-help.com>
34484a
Date: Thu, 19 Oct 2017 10:46:04 +1100
34484a
Subject: [PATCH] (perl #132245) don't try to process a char range with no
34484a
 preceding char
34484a
MIME-Version: 1.0
34484a
Content-Type: text/plain; charset=UTF-8
34484a
Content-Transfer-Encoding: 8bit
34484a
34484a
A range like \N{}-0 eventually results in compilation failing, but
34484a
before that, get_and_check_backslash_N_name() attempts to treat
34484a
the memory before the empty output of \N{} as a character.
34484a
34484a
Petr Písař: Ported to 5.26.1.
34484a
34484a
Signed-off-by: Petr Písař <ppisar@redhat.com>
34484a
---
34484a
 t/lib/warnings/toke | 5 +++++
34484a
 toke.c              | 6 +++---
34484a
 2 files changed, 8 insertions(+), 3 deletions(-)
34484a
34484a
diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke
34484a
index fc51d9f..398ee22 100644
34484a
--- a/t/lib/warnings/toke
34484a
+++ b/t/lib/warnings/toke
34484a
@@ -1651,3 +1651,8 @@ Execution of - aborted due to compilation errors.
34484a
 use utf8;
34484a
 qw∘foo ∞ ♥ bar∘
34484a
 EXPECT
34484a
+########
34484a
+# NAME tr/// range with empty \N{} at the start
34484a
+tr//\N{}-0/;
34484a
+EXPECT
34484a
+Unknown charname '' is deprecated. Its use will be fatal in Perl 5.28 at - line 1.
34484a
diff --git a/toke.c b/toke.c
34484a
index 6f84d2d..6ee7a68 100644
34484a
--- a/toke.c
34484a
+++ b/toke.c
34484a
@@ -2958,9 +2958,9 @@ S_scan_const(pTHX_ char *start)
34484a
 
34484a
                 /* Here, we don't think we're in a range.  If the new character
34484a
                  * is not a hyphen; or if it is a hyphen, but it's too close to
34484a
-                 * either edge to indicate a range, then it's a regular
34484a
-                 * character. */
34484a
-                if (*s != '-' || s >= send - 1 || s == start) {
34484a
+                 * either edge to indicate a range, or if we haven't output any
34484a
+                 * characters yet then it's a regular character. */
34484a
+                if (*s != '-' || s >= send - 1 || s == start || d == SvPVX(sv)) {
34484a
 
34484a
                     /* A regular character.  Process like any other, but first
34484a
                      * clear any flags */
34484a
-- 
34484a
2.13.6
34484a