develooper Front page | perl.perl5.porters | Postings from September 2023

Re: DAVEM TPF Grant#3 June, July, August 2023 report

Thread Previous | Thread Next
From:
wolfsage
Date:
September 14, 2023 12:49
Subject:
Re: DAVEM TPF Grant#3 June, July, August 2023 report
Message ID:
CAJ0K8bg1-WRNRM+XLe1uO5KwpsBOaf6TxRi1Mnw-WfqWLM_WAg@mail.gmail.com
On Fri, Sep 8, 2023 at 10:27 AM Dave Mitchell <davem@iabyn.com> wrote:

> Here is a classic example of the bug. Examine this code carefully:
>
>     @a = qw(aaa bbb);
>     f(@a);
>
>     sub f {
>         # on entry, $_[0] is an alias of $a[0],
>         #           $_[1] is an alias of $a[1],
>         print "@_\n"; # correctly prints "aaa bbb"
>
>         @a = (); # this prematurely frees $_[0] and $_[1]
>
>         # this causes the two just-freed SVs to be reallocated
>         my $x = 'xxx:yyy'; my @x = split /:/, $x;
>
>         # but the two reallocated SVs are still referenced by @_
>         print "@_\n"; # incorrectly prints "xxx yyy"
>     }
>

Well that's terrifying.

+1 from me, thanks Dave!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About