Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/pr104369-1.c

raw
1 /* { dg-additional-options "-Wno-analyzer-too-complex -Wno-analyzer-fd-leak" } */
2 // TODO: remove need for these options
3 /* C only: C++ does not support transparent_union. */
4
5
6 typedef __SIZE_TYPE__ size_t;
7 #define NULL ((void *)0)
8 #define POLLIN 0x001
9
10 typedef struct {
11 unsigned long int __val[(1024 / (8 * sizeof(unsigned long int)))];
12 } __sigset_t;
13
14 typedef unsigned int socklen_t;
15
16 struct timespec {
17 /* [...snip...] */
18 };
19
20 typedef unsigned long int nfds_t;
21
22 struct pollfd {
23 int fd;
24 short int events;
25 short int revents;
26 };
27
28 extern int ppoll(struct pollfd *__fds, nfds_t __nfds,
29 const struct timespec *__timeout, const __sigset_t *__ss);
30
31 struct sockaddr_un {
32 /* [...snip...] */
33 char sun_path[108];
34 };
35
36 typedef union {
37 /* [...snip...] */
38 struct sockaddr_un *__restrict __sockaddr_un__;
39 /* [...snip...] */
40 } __SOCKADDR_ARG __attribute__((transparent_union));
41
42 extern int accept(int __fd, __SOCKADDR_ARG __addr,
43 socklen_t *__restrict __addr_len);
44
45 extern void *calloc(size_t __nmemb, size_t __size)
46 __attribute__((__nothrow__, __leaf__))
47 __attribute__((__malloc__))
48 __attribute__((__alloc_size__(1, 2)));
49
50 extern void *realloc(void *__ptr, size_t __size)
51 __attribute__((__nothrow__, __leaf__))
52 __attribute__((__warn_unused_result__))
53 __attribute__((__alloc_size__(2)));
54
55 extern void exit(int __status)
56 __attribute__((__nothrow__, __leaf__))
57 __attribute__((__noreturn__));
58
59 int main() {
60 int rc;
61 int nsockets = 1;
62 struct pollfd *pollfds, *newpollfds;
63 struct sockaddr_un remote;
64 socklen_t len = sizeof(remote);
65
66 pollfds = (struct pollfd *) calloc(1, sizeof(struct pollfd));
67 if (!pollfds) {
68 exit(1);
69 }
70
71 while (1) {
72 rc = ppoll(pollfds, nsockets, NULL, NULL);
73 if (rc < 0) {
74 continue;
75 }
76
77 if (pollfds[0].revents & POLLIN) {
78 nsockets++;
79 newpollfds = (struct pollfd *) realloc(pollfds, nsockets * sizeof(*pollfds));
80 if (!newpollfds) {
81 exit(1);
82 }
83 pollfds = newpollfds;
84 pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
85 /* { dg-error "could not convert '& remote' from 'sockaddr_un*' to '__SOCKADDR_ARG'" "G++ doesn't support transparent_union" { target c++ } .-1 } */
86 }
87 }
88 return 0;
89 }