This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix #127855, in Perl_sv_setpvn() we have to overallocate to enable COW
authorYves Orton <demerphq@gmail.com>
Fri, 8 Apr 2016 18:46:43 +0000 (20:46 +0200)
committerYves Orton <demerphq@gmail.com>
Fri, 8 Apr 2016 19:30:50 +0000 (21:30 +0200)
We need to overallocate by 2 to do COW strings. One for the null,
one for the refcount.

sv.c

diff --git a/sv.c b/sv.c
index 0200679..68df702 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4891,7 +4891,7 @@ Perl_sv_setpvn(pTHX_ SV *const sv, const char *const ptr, const STRLEN len)
     }
     SvUPGRADE(sv, SVt_PV);
 
-    dptr = SvGROW(sv, len + 1);
+    dptr = SvGROW(sv, len + 2);
     Move(ptr,dptr,len,char);
     dptr[len] = '\0';
     SvCUR_set(sv, len);