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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to