summaryrefslogtreecommitdiff
path: root/sv.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2016-04-08 21:25:20 +0200
committerYves Orton <demerphq@gmail.com>2016-04-08 21:30:50 +0200
commitbcc9f606509ad2fad50e16f081103451b7dc49e1 (patch)
treea6db50d6af82c1b496504bf7e80902d0ebf66f0b /sv.h
parente19cb11142087974d956f263d24e146b968025d5 (diff)
downloadperl-bcc9f606509ad2fad50e16f081103451b7dc49e1.tar.gz
More generalized fix for #127855, overallocate in SvGROW and not just sv_grow()
If we overallocate in SvGROW() and not just sv_grow() we can ensure we have more cases where we can COW. We need to ensure we always have room for a null and a reference count.
Diffstat (limited to 'sv.h')
-rw-r--r--sv.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/sv.h b/sv.h
index bfda6bf6cb..0c6e6d49b1 100644
--- a/sv.h
+++ b/sv.h
@@ -2111,12 +2111,15 @@ See also C<L</PL_sv_yes>> and C<L</PL_sv_no>>.
#ifdef PERL_ANY_COW
# define SvGROW(sv,len) \
- (SvIsCOW(sv) || SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
+ (SvIsCOW(sv) || SvLEN(sv) < ((len)+2) ? sv_grow(sv,(len)+2) : SvPVX(sv))
+# define SvGROW_mutable(sv,len) \
+ (SvLEN(sv) < ((len)+2) ? sv_grow(sv,(len)+2) : SvPVX_mutable(sv))
#else
-# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
+# define SvGROW(sv,len) \
+ (SvLEN(sv) < ((len)+1) ? sv_grow(sv,(len)+1) : SvPVX(sv))
+# define SvGROW_mutable(sv,len) \
+ (SvLEN(sv) < ((len)+1) ? sv_grow(sv,(len)+1) : SvPVX_mutable(sv))
#endif
-#define SvGROW_mutable(sv,len) \
- (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX_mutable(sv))
#define Sv_Grow sv_grow
#define CLONEf_COPY_STACKS 1