Skip to content
Snippets Groups Projects
  1. Jul 11, 2014
  2. Jul 10, 2014
    • Jordan Rose's avatar
      [analyzer] Check for code testing a variable for 0 after using it as a denominator. · 00a1ef80
      Jordan Rose authored
      This new checker, alpha.core.TestAfterDivZero, catches issues like this:
      
        int sum = ...
        int avg = sum / count; // potential division by zero...
        if (count == 0) { ... } // ...caught here
      
      Because the analyzer does not necessarily explore /all/ paths through a program,
      this check is restricted to only work on zero checks that immediately follow a
      division operation (/ % /= %=). This could later be expanded to handle checks
      dominated by a division operation but not necessarily in the same CFG block.
      
      Patch by Anders Rönnholm! (with very minor modifications by me)
      
      git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212731 91177308-0d34-0410-b5e6-96231b3b80d8
      00a1ef80
Loading