[comp.lang.perl] core dumping bug w/ sort?

tchrist@convex.com (Tom Christiansen) (02/22/90)

Here is a reduced piece of code that will generate a quick
core dump on  a Sun and a Convex.  Just clip and run.  The
weird thing is that the sort sub seems is being called with
null args that just aren't in the passed list.  I suppose it's
possible that I'm doing something stupid here, but even if so, 
I don't really think I deserve a coredump.

--tom

#=================  CLIP HERE =============================================
# $MANSECT = "1nlp6823457tX";  # Add 'X' to avoid core dump
$MANSECT = "1nlp6823457t";  # notice no 'X' here; we're going to dump core

@foo = &sortem;
print "foo is @foo\n";

sub sortem {
    @list = ('foo.3', 'bar.X');
    return sort bysection @list;
}

sub bysection {
    print STDERR "comparing \"$a\" with \"$b\"\n";
    $a1 = index($MANSECT,substr($a,rindex($a,'.')+1,1));
    $a2 = index($MANSECT,substr($b,rindex($b,'.')+1,1));
    if ($a1 == $a2) {
	return 0;
    } else {
	return ($a2 < 0 || $a1 < $a2) ? -1 : 1;
    }
}
#=================  CLIP HERE =============================================
--

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"