Push a new stack in sv_recode_to_utf8
authorFather Chrysostomos <sprout@cpan.org>
Sat, 23 Nov 2013 04:34:17 +0000 (20:34 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 23 Nov 2013 05:20:37 +0000 (21:20 -0800)
That prevents this from happening under STRESS_REALLOC:

$ ./perl -Ilib -Mencoding=johab -e '(chr(0x7f) eq "\x7f")'
Use of the encoding pragma is deprecated at -e line 0.
perl(3939) malloc: *** error for object 0x7fac20c03968: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

(That is an excerpt from t/uni/chr.t.)

It may also fix other instances of encoding.pm crashing, which I had
almost vowed not to do.  Oh well.

Constant folding is generally expected not to reallocate the stack,
because it should never need to extend it, just reduce the number of
items on it.

sv_recode_to_utf8 breaks that assumption.

sv.c

diff --git a/sv.c b/sv.c
index 2c83597d5c6045ed5fa4f7a1dc7718c81a464da5..1c226156a4bbcdfcaf87ccd0372e98c33088e98b 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -14072,6 +14072,7 @@ Perl_sv_recode_to_utf8(pTHX_ SV *sv, SV *encoding)
        const char *s;
        dSP;
        ENTER;
+       PUSHSTACK;
        SAVETMPS;
        save_re_context();
        PUSHMARK(sp);
@@ -14100,6 +14101,7 @@ Perl_sv_recode_to_utf8(pTHX_ SV *sv, SV *encoding)
            SvCUR_set(sv, len);
        }
        FREETMPS;
+       POPSTACK;
        LEAVE;
        if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
            /* clear pos and any utf8 cache */