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