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

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

Open
BebeSparkelSparkel opened this issue Dec 23, 2024 · 0 comments
Open

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

BebeSparkelSparkel opened this issue Dec 23, 2024 · 0 comments

Comments

@BebeSparkelSparkel
Copy link

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.

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

2 participants