<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 divide by zero"
href="https://bugs.llvm.org/show_bug.cgi?id=41452">41452</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False positive divide by zero
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>7.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>khourig@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The code:
/* --- read_n.c --- */
#include <unistd.h>
ssize_t read_n(void *p, size_t size, size_t n) {
size_t len = n * size;
if (size && len / size != n) return 0;
return len ? read(0, p, len) / size : 0;
}
/* ---------------- */
The output:
$ clang-7 -Wall --analyze -c read_n.c
read_n.c:7:34: warning: Division by zero
return len ? read(0, p, len) / size : 0;
~~~~~~~~~~~~~~~~^~~~~~
1 warning generated.
Extra info (from Xcode - How can I get this from clang?)
Assuming 'size' is 0
Assuming 'len' is not 0
But, if size is 0, len will also be 0.</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>