From 1d3e71cba3c79b6d3709c8bdef438bd785dfcb9e Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 20 Sep 2023 14:32:04 +1000 Subject: [PATCH] split: prevent a panic in some cases with \G Fixes #16971 --- pp.c | 2 ++ t/op/split.t | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pp.c b/pp.c index d29356a2efb9..72d0369b2b08 100644 --- a/pp.c +++ b/pp.c @@ -6877,6 +6877,8 @@ PP_wrapped(pp_split, else trailing_empty = 0; } else { + if (m < s) + m = s; dstr = newSVpvn_flags(s, m-s, flags); XPUSHs(dstr); } diff --git a/t/op/split.t b/t/op/split.t index 9a967adb1929..a7c1f958d68f 100644 --- a/t/op/split.t +++ b/t/op/split.t @@ -7,7 +7,7 @@ BEGIN { require './charset_tools.pl'; } -plan tests => 197; +plan tests => 198; $FS = ':'; @@ -725,3 +725,4 @@ SKIP: { }, "special-case pattern for $prog"); } } +fresh_perl_is('split /00|0\G/, "000"', '', {}, "split with \\G doesn't panic");