[llvm-bugs] [Bug 41452] New: False positive divide by zero
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Apr 10 07:40:15 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41452
Bug ID: 41452
Summary: False positive divide by zero
Product: clang
Version: 7.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: khourig at yahoo.com
CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190410/b1351bca/attachment.html>
More information about the llvm-bugs
mailing list