[llvm-bugs] [Bug 46346] New: Add a checker to detected bad checks of mmap() return value

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 16 02:50:01 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46346

            Bug ID: 46346
           Summary: Add a checker to detected bad checks of mmap() return
                    value
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: OpenBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: estetus at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

The mmap() POSIX function returns MAP_FAILED or -1 when an error occurs. A
common mistake is to check the return value for 0 instead.

https://pubs.opengroup.org/onlinepubs/009695399/functions/mmap.html

Example:

```
        buflen = statbuf.st_size;
        buf = mmap(NULL, buflen, PROT_READ, MAP_PRIVATE|MAP_POPULATE, fd, 0);
-       if (!buf)
+       if (buf == MAP_FAILED)
                goto err;

        *data = buf;
```

-- 
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/20200616/f7425006/attachment.html>


More information about the llvm-bugs mailing list