# Used in various places of output.
my $fancy = '-' x 80 . "\n";
+sub safe_div($$)
+{
+ my ($x, $y) = @_;
+ return ($y == 0 ? 0 : $x / $y);
+}
+
#-----------------------------------------------------------------------------
# Argument and option handling
#-----------------------------------------------------------------------------
# Read body of input file.
while (<INPUTFILE>) {
s/#.*$//; # remove comments
- if (s/^(\d+)\s+//) {
+ if (s/^(-?\d+)\s+//) {
my $lineNum = $1;
my $CC = line_to_CC($_);
defined($currFuncCC) || die;
$x = -1 unless defined $x;
$y = -1 unless defined $y;
- my $cmp = $y <=> $x; # reverse sort
+ my $cmp = abs($y) <=> abs($x); # reverse sort of absolute size
if (0 != $cmp) {
return $cmp;
}
sub commify ($) {
my ($val) = @_;
- 1 while ($val =~ s/^(\d+)(\d{3})/$1,$2/);
+ 1 while ($val =~ s/^(-?\d+)(\d{3})/$1,$2/);
return $val;
}
# Stop when we've reached all the thresholds
my $reached_all_thresholds = 1;
foreach my $i (0 .. scalar @thresholds - 1) {
- my $prop = $curr_totals[$i] * 100 / $summary_CC->[$sort_order[$i]];
+ my $prop = safe_div(abs($curr_totals[$i] * 100),
+ abs($summary_CC->[$sort_order[$i]]));
$reached_all_thresholds &&= ($prop >= $thresholds[$i]);
}
last if $reached_all_thresholds;
foreach (my $i = 0; $i < @$summary_CC; $i++) {
$percent_printed_CC->[$i] =
sprintf("%.0f",
- $printed_totals_CC->[$i] / $summary_CC->[$i] * 100);
+ safe_div(abs($printed_totals_CC->[$i]),
+ abs($summary_CC->[$i] * 100)));
}
my $pp_CC_col_widths = compute_CC_col_widths($percent_printed_CC);
print($fancy);