Skip to content

scan-build division by zero while calculating the stats #120977

Open
@BebeSparkelSparkel

Description

@BebeSparkelSparkel
scan-build: Analysis run complete.
Illegal division by zero at /home/wjr/llvm-project/build/bin/scan-build line 500.

Line 500

  my $PercentAborted = sprintf("%.2f", $Aborted / $TotalFunctions * 100);

in the function CalcStats

sub CalcStats {
  my $Stats = shift;

  my $TotalBlocks = 0;
  my $UnreachedBlocks = 0;
  my $TotalFunctions = scalar(@$Stats);
  my $BlockAborted = 0;
  my $WorkListAborted = 0;
  my $Aborted = 0;

  # Calculate the unique files
  my $FilesHash = {};

  foreach my $Row (@$Stats) {
    $FilesHash->{$Row->{Filename}} = 1;
    $TotalBlocks += $Row->{Total};
    $UnreachedBlocks += $Row->{Unreachable};
    $BlockAborted++ if $Row->{Aborted} eq 'yes';
    $WorkListAborted++ if $Row->{Empty} eq 'no';
    $Aborted++ if $Row->{Aborted} eq 'yes' || $Row->{Empty} eq 'no';
  }

  my $TotalFiles = scalar(keys(%$FilesHash));

  # Calculations
  my $PercentAborted = sprintf("%.2f", $Aborted / $TotalFunctions * 100);
  my $PercentBlockAborted = sprintf("%.2f", $BlockAborted / $TotalFunctions
      * 100);
  my $PercentWorkListAborted = sprintf("%.2f", $WorkListAborted /
      $TotalFunctions * 100);
  my $PercentBlocksUnreached = sprintf("%.2f", $UnreachedBlocks / $TotalBlocks
      * 100);

  my $StatsString = "Analyzed $TotalBlocks blocks in $TotalFunctions functions"
    . " in $TotalFiles files\n"
    . "$Aborted functions aborted early ($PercentAborted%)\n"
    . "$BlockAborted had aborted blocks ($PercentBlockAborted%)\n"
    . "$WorkListAborted had unfinished worklists ($PercentWorkListAborted%)\n"
    . "$UnreachedBlocks blocks were never reached ($PercentBlocksUnreached%)\n";

  return $StatsString;
}

The command was:

#!/bin/sh

# Create a clean output directory
REPORT_DIR="/tmp/iked-analysis"
mkdir -p "$REPORT_DIR"

~/llvm-project/build/bin/scan-build \
  --status-bugs \
  --use-cc=clang \
  -analyze-headers \
  -constraints range \
  -enable-checker alpha.core.PointerArithmetic \
  -enable-checker alpha.core.PointerSub \
  -enable-checker alpha.security.ArrayBound \
  -enable-checker alpha.unix.Stream \
  -enable-checker core.CallAndMessage \
  -enable-checker core.DivideZero \
  -enable-checker core.NullDereference \
  -enable-checker core.uninitialized.ArraySubscript \
  -enable-checker core.uninitialized.Assign \
  -enable-checker core.uninitialized.Branch \
  -enable-checker deadcode.DeadStores \
  -enable-checker security \
  -enable-checker unix.API \
  -enable-checker unix.Malloc \
  -enable-checker unix.cstring.BadSizeArg \
  -enable-checker unix.cstring.NullArg \
  -maxloop 30 \
  -o "$REPORT_DIR" \
  -stats \
  -v \
  make \
  CFLAGS="-Wall -I. -Wstrict-prototypes -Wmissing-prototypes \
  -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual \
  -Wsign-compare -DDEBUG"

in the OpenBSD iked src directory.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions