[llvm-bugs] [Bug 43670] New: analyzer does not know that failed syscalls set errno

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 14 03:01:41 PDT 2019


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

            Bug ID: 43670
           Summary: analyzer does not know that failed syscalls set errno
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: npl at chello.at
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

The following code will produce a report, even though the analyzer could/should
deduce that errno is set to non-zero if socket returns < 0.
Adding the __builtin_unreachable fixes the report, but this should be automatic
for reading errno after entering a branch that requires a failed syscall.


#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>

extern int dosomething(char *);


static int connect_socket(char **mname) {
        int ret;
        *mname = (char *)malloc(PATH_MAX);


  int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
  if (fd < 0) {
    ret = errno;
    // if (ret == 0)
    //  __builtin_unreachable();
    free(*mname);
    return ret;
  }

  {
    ret = recv(fd, *mname, PATH_MAX, 0);
    if (ret > 0) return 0;
  }
  close(fd);
  return ret;
}

int do_init()
{
        char *mname;
        int ret = connect_socket(&mname);
        if (ret)
                return ret;

        return dosomething(mname);
}

-- 
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/20191014/4f1a68c6/attachment.html>


More information about the llvm-bugs mailing list