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

Re: [ID 20010821.007] sort stupidness caused segfault

Thread Previous | Thread Next
From:
Hugo van der Sanden
Date:
April 15, 2002 07:31
Subject:
Re: [ID 20010821.007] sort stupidness caused segfault
Message ID:
200204151434.g3FEYcQ30904@crypt.compulink.co.uk
A while back, "Abigail" <abigail@foad.org> wrote:
:On Wed, Aug 22, 2001 at 07:17:07AM -0400, John P. Linderman wrote:
:> > just stuffing around being stupid with sort {} and ..
:> > 
:> > gateway:~/tmp# cat rand
:> > #!/usr/bin/perl
:> > @a = (1, 2, 3, 4, 5, 6, 7, 8, 9);
:> > @a = sort {
:> >         @a = sort {
:> >                 @a = sort {
:> >                         @a = sort {
:> >                                 int rand (2) - 2;
:> >                         }
:> >                         int rand (2) - 2;
:> >                 }
:> >                 int rand (2) - 2;
:> >         } @a;
:> >         int rand (2) - 2;
:> > } @a;
:> > print join '', @a;
:> > gateway:~/tmp# ./rand
:> > Segmentation fault
:> 
:> I don't think this is directly related to sort because
:> a) it happens both with the 5.6 qsort and the 5.7 merge sort and
:> b) it goes away if you pass @a to the two innermost invocations
:>    (as is done on the outermost invocations) before returning the
:>    random value.
:> 
:> Still, as the documentation says,
:>    The comparison function is required to behave.
:
:If you replace all the occurances of 'int rand (2) - 2' in the above
:code with 0, it still core dumps.
:
:My guess is that the problem is the modification of @a during the sort.

This still dumps with latest bleadperl. Here's a shorter test case:
  ./perl -wle '@a=(1..8); @a = sort { @a = (0) } @a'
... and each occurrence of @a appears to be required for the coredump.

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