[perl #77692] substr causes panic: sv_len_utf8 cache...
authorFather Chrysostomos <sprout@cpan.org>
Thu, 10 Feb 2011 17:20:14 +0000 (09:20 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 10 Feb 2011 17:20:49 +0000 (09:20 -0800)
commite27c778fa5810b784abf1dc38af460227e408d37
tree00e608d0bde97e52a3ee8f5094e58e05b5339801
parent9a0dc6e4c3a9ae91c1101b1179e22c93bb77a4cb
[perl #77692] substr causes panic: sv_len_utf8 cache...

pp_substr contains this comment, which was added in perl 5.0 alpha 2
(commit 79072805bf63):

    PUSHs(TARG); /* avoid SvSETMAGIC here */

Calling set-magic when substr returns an lvalue will cause its argu-
ment to be stringified even if the lvalue is not assigned to. That’s
why set-magic has to be avoided.

But the result is that utf8 caches (stored in magic) on TARG are not
reset properly.

Since substr lvalues now follow a different code path (and do not use
TARG at all), it’s perfectly safe to call set-magic at this point.
It’s also the right thing to do in case of other types of magic that
might get attached to TARG.
pp.c
t/re/substr.t