<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - False positive division by zero"
   href="https://bugs.llvm.org/show_bug.cgi?id=39239">39239</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive division by zero
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>benbuck@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>To reproduce:

$ cat false_div_zero.c
int false_div_zero(int size, int nitems) {
    int len = nitems * size;
    if (size && ((len / size) != nitems))
        return 0;
    return len ? (len / size) : 0;
}

$ clang --analyze false_div_zero.c
false_div_zero.c:5:23: warning: Division by zero
    return len ? (len / size) : 0;
                  ~~~~^~~~~~
1 warning generated.


The analyzer seems to assume on line 3 that size is zero, and on line 5 that
len is not zero. However, if size is zero on line 2, then len should also be
zero.

Please note that this reproduction case is a very simplified version of the
relevant part of the gzfwrite() implementation in gzwrite.c from zlib.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>