From a10eae290937db109954431d254a9a25287f190b Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Thu, 25 Jul 2013 16:52:59 -0700 Subject: [PATCH] Make @- and @+ return correct offsets beyond 2**31 --- mg.c | 10 +++++----- t/bigmem/regexp.t | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mg.c b/mg.c index c2d2186..b7f9c05 100644 --- a/mg.c +++ b/mg.c @@ -661,21 +661,21 @@ Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) const REGEXP * const rx = PM_GETRE(PL_curpm); if (rx) { const I32 paren = mg->mg_len; - I32 s; - I32 t; + SSize_t s; + SSize_t t; if (paren < 0) return 0; if (paren <= (I32)RX_NPARENS(rx) && (s = RX_OFFS(rx)[paren].start) != -1 && (t = RX_OFFS(rx)[paren].end) != -1) { - I32 i; + SSize_t i; if (mg->mg_obj) /* @+ */ i = t; else /* @- */ i = s; - if (i > 0 && RX_MATCH_UTF8(rx)) { + if (RX_MATCH_UTF8(rx)) { const char * const b = RX_SUBBEG(rx); if (b) i = RX_SUBCOFFSET(rx) + @@ -683,7 +683,7 @@ Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) (U8*)(b-RX_SUBOFFSET(rx)+i)); } - sv_setiv(sv, i); + sv_setuv(sv, i); } } } diff --git a/t/bigmem/regexp.t b/t/bigmem/regexp.t index da7bf26..9404f2c 100644 --- a/t/bigmem/regexp.t +++ b/t/bigmem/regexp.t @@ -12,7 +12,7 @@ $ENV{PERL_TEST_MEMORY} >= 2 $Config{ptrsize} >= 8 or skip_all("Need 64-bit pointers for this test"); -plan(4); +plan(5); # [perl #116907] # ${\2} to defeat constant folding, which in this case actually slows @@ -31,3 +31,5 @@ is $result," -a-b-c-d-", 'scalar //g hopping past the 2**31 threshold'; pos $x = 2**31+3; $x =~ /./g; is "$'", 'efg', q "$' after match against long string"; +is "$-[0],$+[0]", '2147483651,2147483652', + '@- and @+ after matches past 2**31'; -- 2.7.4