]> granicus.if.org Git - clang/commit
[analyzer] Check for code testing a variable for 0 after using it as a denominator.
authorJordan Rose <jordan_rose@apple.com>
Thu, 10 Jul 2014 16:10:52 +0000 (16:10 +0000)
committerJordan Rose <jordan_rose@apple.com>
Thu, 10 Jul 2014 16:10:52 +0000 (16:10 +0000)
commit00a1ef8023158119fb897948b384a6bc8c96d801
tree07abe08da3f5f92f612f2c5aebed6f0e91bf4567
parent1ad1932c80ad213af67ff929f86b612eb7fd7c82
[analyzer] Check for code testing a variable for 0 after using it as a denominator.

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
include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
lib/StaticAnalyzer/Checkers/CMakeLists.txt
lib/StaticAnalyzer/Checkers/Checkers.td
lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp [new file with mode: 0644]
test/Analysis/test-after-div-zero.c [new file with mode: 0644]