This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Don't overallocate space for cloned SV
authorKarl Williamson <public@khwilliamson.com>
Sun, 27 Nov 2011 22:45:22 +0000 (15:45 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 13 Jan 2012 16:58:35 +0000 (09:58 -0700)
The length passed to _new_invlist() is in elements and not bytes, so
this was overallocating space because the number of bytes is multiplied
by a platform-dependent value.

regcomp.c

index ba9159e..fac23f5 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6751,7 +6751,9 @@ S_invlist_clone(pTHX_ SV* const invlist)
     /* Return a new inversion list that is a copy of the input one, which is
      * unchanged */
 
-    SV* new_invlist = _new_invlist(SvCUR(invlist));
+    /* Need to allocate extra space to accommodate Perl's addition of a
+     * trailing NUL to SvPV's, since it thinks they are always strings */
+    SV* new_invlist = _new_invlist(invlist_len(invlist) + 1);
     STRLEN length = SvCUR(invlist);
 
     PERL_ARGS_ASSERT_INVLIST_CLONE;