This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t clobber all magic when clobbering vstring
authorFather Chrysostomos <sprout@cpan.org>
Fri, 23 Dec 2011 22:28:33 +0000 (14:28 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 23 Dec 2011 22:45:55 +0000 (14:45 -0800)
commit190e89f069481aa08def70f73170ade1d6d1fca9
tree49bce15d1828829087717ef3ec4a3e056de5147f
parent0b7a369cae77008a12eaaee38c4a63fd344fca22
Don’t clobber all magic when clobbering vstring

This code in sv_setsv, introduced in ece467f9b3, can’t possi-
bly be right:

    if ( SvVOK(dstr) )
    {
/* need to nuke the magic */
mg_free(dstr);
    }

And here is a test to prove it:

sub TIESCALAR { bless[]}
sub STORE {}
tie $@, "";
$@ = v0;
warn tied $@; # main=ARRAY(0xc0ffee)
$@ = 3;
warn tied $@; # something’s wrong

It blows away tiedness.

You could do that to any variable.

Let’s see:

$! = v0;
$! = 3;
open foo, 'oentuhaeontu' or die $!;  # 3 at - line 3.

Youch!

Let’s just free vstring magic, shall we?
sv.c
t/op/ver.t