Subject: | SIGSEGV on calling sort comparison routine |
Starting the attached perl script under coverage control, and it crashes:
=========================================================================
prompt% uname -a
SunOS mach0 5.8 Generic_117350-13 sun4u sparc SUNW,Sun-Fire-280R
prompt% Devel::Cover 0.52: Collecting coverage data for branch, condition, pod, statement, subroutine and time.
Selecting packages matching:
Ignoring packages matching:
/Devel/Cover[./]
Ignoring packages in:
.
/opt/perl_5.8.5/lib/sun4-solaris-thread-multi
/opt/perl_5.8.5/share/lib
Segmentation fault
prompt %
=========================================================================
If you expand the body of the comparison routine into the block after the sort, coverage works perfectly.
Using no coverage at all, any method works fine.
ccVersionsComparable
(
'element@@',
{ '/main/' => 1, '/main/branch/' => 1 }
);
# compare two branches
sub ccBranchCmp
{
# element, branch separator ('/' or '\'), branches split to arrays
my $element = $_[0];
my $brs = substr $_[1],0,1;
my @br0 = split /[\/\\]/,substr $_[1],1;
my @br1 = split /[\/\\]/,substr $_[2],1;
# common subbranch
for (1 .. scalar (@br0 <= @br1 ? @br0 : @br1))
{
# get next portion of branch
my ($sb0,$sb1) = (shift @br0,shift @br1);
# branch portions still are equal
next if $sb0 eq $sb1;
# compare versions, where branches fork
# ...
($sb0,$sb1) = ('/main/0','/main/1');
for ($sb0,$sb1) { s/.*?(\d+)$/$1/ }
return $sb0 <=> $sb1;
}
# br0 is subbranch of br1
return -1 if @br1;
# br1 is subbranch of br0
return +1 if @br0;
# b0 and b1 are identical
return 0;
}
# check comparability of versions
sub ccVersionsComparable
{
my ($element,$branch) = @_;
# branch comparison
my @branch = sort { ccBranchCmp($element,$a,$b) } keys %$branch;
# ...
}