develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [ID 20010821.007] sort stupidness caused segfault

Thread Previous | Thread Next
From:
John P. Linderman
Date:
August 22, 2001 04:17
Subject:
Re: [ID 20010821.007] sort stupidness caused segfault
Message ID:
200108221117.HAA27508@raptor.research.att.com
> 
> This is a bug report for perl from root@ws.com.au,
> generated with the help of perlbug 1.33 running under perl v5.6.1.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> 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.
A sort implementor should be able to pick any array element
and be confident that the comparison function will return 0
when the element is compared with itself.  There are sort
implementations where the use of such sentinels lead to
significant savings.  It happens that neither the qsort nor
the merge sort implementation rely on that, so we're spared
the difficult choice of how much to penalize well-behaved
users to spare bozos a core dump.

We return you now to the hands of people better qualified to
determine the real cause of the core dump.
-- jpl




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