Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/fd-pr108633.c

raw
1 /* Reduced from qemu-7.2.0's tests/qtest/libqtest.c. */
2
3 #define EINTR 4
4
5 #define g_assert_cmpint(n1, cmp, n2) \
6 do { \
7 gint64 __n1 = (n1), __n2 = (n2); \
8 if (__n1 cmp __n2) ; else \
9 g_assertion_message_cmpnum ("", __FILE__, __LINE__, __func__, \
10 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'i'); \
11 } while (0)
12
13 typedef __SIZE_TYPE__ size_t;
14 typedef unsigned int __socklen_t;
15 extern int snprintf (char *__restrict __s, size_t __maxlen,
16 const char *__restrict __format, ...)
17 __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4)));
18 typedef __socklen_t socklen_t;
19 extern int *__errno_location (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
20 #define errno (*__errno_location ())
21 typedef signed long gint64;
22 typedef char gchar;
23 extern
24 void g_assertion_message_cmpnum (const char *domain,
25 const char *file,
26 int line,
27 const char *func,
28 const char *expr,
29 long double arg1,
30 const char *cmp,
31 long double arg2,
32 char numtype);
33 enum __socket_type
34 {
35 SOCK_STREAM = 1,
36 /* [...snip...] */
37 };
38
39 typedef unsigned short int sa_family_t;
40
41 typedef union {
42 const struct sockaddr *__restrict __sockaddr__;
43 /* [...snip...] */
44 } __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__));
45
46 extern int socket (int __domain, int __type, int __protocol)
47 __attribute__ ((__nothrow__ , __leaf__));
48 extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
49 __attribute__ ((__nothrow__ , __leaf__));
50 extern int listen (int __fd, int __n)
51 __attribute__ ((__nothrow__ , __leaf__));
52
53 struct sockaddr_un
54 {
55 sa_family_t sun_family;
56 char sun_path[108];
57 };
58
59 int qtest_socket_server(const char *socket_path)
60 {
61 struct sockaddr_un addr;
62 int sock;
63 int ret;
64
65 sock = socket(1, SOCK_STREAM, 0); /* { dg-message "when 'socket' fails" } */
66 g_assert_cmpint(sock, !=, -1); /* this isn't marked "noreturn" */
67
68 addr.sun_family = 1;
69 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path);
70
71 do {
72 ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
73 } while (ret == -1 && errno == EINTR);
74 g_assert_cmpint(ret, !=, -1);
75 ret = listen(sock, 1); /* { dg-warning "'listen' on possibly invalid file descriptor 'sock'" } */
76 g_assert_cmpint(ret, !=, -1);
77
78 return sock;
79 }