Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perl crashing on sort()? #2180

Closed
p5pRT opened this issue Jul 9, 2000 · 5 comments
Closed

perl crashing on sort()? #2180

p5pRT opened this issue Jul 9, 2000 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 9, 2000

Migrated from rt.perl.org#3476 (status was 'resolved')

Searchable as RT3476$

@p5pRT
Copy link
Author

p5pRT commented Jul 9, 2000

From auto71426@hushmail.com

The attached script I've written manages to crash perl. Unfortunately I'm
not a Perl expert so I'm not sure if it something that I am doing wrong
or if this is perl's fault.

$ perl --version

This is perl, version 5.005_03 built for i386-linux

(Standard perl that comes with RedHat 6.2).

IMPORTANT NOTICE​: If you are not using HushMail, this message could have been read easily by the many people who have access to your open personal email messages.
Get your FREE, totally secure email address at http​://www.hushmail.com.

@p5pRT
Copy link
Author

p5pRT commented Jul 9, 2000

From auto71426@hushmail.com

comments.db

@p5pRT
Copy link
Author

p5pRT commented Jul 9, 2000

From auto71426@hushmail.com

sort-2.pl

@p5pRT
Copy link
Author

p5pRT commented Jul 10, 2000

From [Unknown Contact. See original ticket]

At 15​:38 +0200 2000-07-09, auto71426@​hushmail.com wrote​:

The attached script I've written manages to crash perl [5..5_03,
Redhat 6.2 for 1386]

The script (which I have not run) contains​:

  foreach $i (sort bythread @​allcomments){
...
sub bythread {
  my(@​a) = "";
  my(@​b) = "";
  @​a = split(/\|/,$a);
  @​b = split(/\|/,$b);
  $a[0] <=> $b[0];

}

A couple of things. Firstly, the man page says

  The comparison function is required to behave. If
  it returns inconsistent results (sometimes saying
  `$x[1]' is less than `$x[2]' and sometimes saying
  the opposite, for example) the results are not
  well-defined.

"are not well-defined" used to be a euphemism for "will almost
certainly be absent because perl uses the C library sort function,
which, on many platforms, dumps core when presented with an
ill-behaved comparison function."; however, 5.005_03 uses its own
sort function, and is much less prone to dumping core. But it's not
entirely immune. So check your comparison function carefully to
satisfy yourself that it's well-behaved for all possible data pairs
you might throw at it.

Secondly, the current version of Perl, 5.6.0, incorporates a bug fix
(change 4417) headed "avoid coredump on C<sort { my $c; return $a cmp
$b } ...>", which is fairly close to what you're doing. So you might
want to try building from the source at
<http​://www.cpan.com/src/latest.tar.gz> and see if a new perl fixes
your problem.

@p5pRT
Copy link
Author

p5pRT commented Sep 11, 2004

@smpeters - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant