This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv_utf8_upgrade_flags_grow(): Alloc extra byte if empty
authorKarl Williamson <khw@cpan.org>
Tue, 5 Feb 2019 05:09:31 +0000 (22:09 -0700)
committerKarl Williamson <khw@cpan.org>
Tue, 5 Feb 2019 16:31:45 +0000 (09:31 -0700)
People may call this expecting that the 'extra' parameter is on top of
whatever is in there.  If something is in there, that already includes a
NUL, but if nothing is in there, for safety, add a byte to the request.

sv.c

diff --git a/sv.c b/sv.c
index b3c4024..0a4a2e5 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3518,7 +3518,8 @@ Perl_sv_utf8_upgrade_flags_grow(pTHX_ SV *const sv, const I32 flags, STRLEN extr
     }
 
     if (SvCUR(sv) == 0) {
-       if (extra) SvGROW(sv, extra);
+        if (extra) SvGROW(sv, extra + 1); /* Make sure is room for a trailing
+                                             byte */
     } else { /* Assume Latin-1/EBCDIC */
        /* This function could be much more efficient if we
         * had a FLAG in SVs to signal if there are any variant