develooper Front page | perl.perl5.porters | Postings from April 2002

Re: [ID 20010823.012] Core dump when redefining sort sub

Thread Previous | Thread Next
From:
Hugo van der Sanden
Date:
April 15, 2002 07:30
Subject:
Re: [ID 20010823.012] Core dump when redefining sort sub
Message ID:
200204151434.g3FEYda30908@crypt.compulink.co.uk
gamma@mintaka.iern.disa.mil wrote:
:Perl gives a segmentation fault and core dump when redefining
:sort subroutine and calling it via goto &NAME. E.g
:
:@sorted = sort foo @myarray
:
:sub foo {
:  goto &sortsub
:}
:
:sub sortsub{
:#sort code
:}

Just found this bug report back. I can confirm that it still coredumps
in latest bleadperl. Here's the complete testcase:
  crypt% ./perl -wle 'sub s1 { goto &s2 } sub s2 { $a cmp $b } print sort s1 (3, 2, 1)'
  Use of uninitialized value in string comparison (cmp) at -e line 1.
  Use of uninitialized value in string comparison (cmp) at -e line 1.
  Segmentation fault (core dumped)
  crypt% 

I don't really understand what is going on here, but I suspect that
it may relate to the behaviour near pp_sort.c:1467:
                SAVEVPTR(CvROOT(cv)->op_ppaddr);
                CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
... which I suspect is modifying the last op of the sortsub to change
how it returns. If I'm right, this modification is then bypassed by
the goto; it would also cause problems with a sortsub that wanted
to call itself recursively (directly or indirectly) or redefine
itself (hence the caveat).

Does anyone understand this well enough to tell me whether I'm right,
and explain what is really going on here?

Hugo

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