This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make @- and @+ return correct offsets beyond 2**31
authorFather Chrysostomos <sprout@cpan.org>
Thu, 25 Jul 2013 23:52:59 +0000 (16:52 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 25 Aug 2013 19:23:59 +0000 (12:23 -0700)
mg.c
t/bigmem/regexp.t

diff --git a/mg.c b/mg.c
index c2d2186..b7f9c05 100644 (file)
--- 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);
                }
        }
     }
index da7bf26..9404f2c 100644 (file)
@@ -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';