| 1 |
/* { dg-require-effective-target sockets } */ |
| 2 |
/* { dg-skip-if "" { powerpc*-*-aix* } } */ |
| 3 |
/* { dg-skip-if "PR analyzer/107750" { *-*-solaris2* } } */ |
| 4 |
|
| 5 |
#include <sys/socket.h> |
| 6 |
#include <sys/un.h> |
| 7 |
#include <unistd.h> |
| 8 |
#include <errno.h> |
| 9 |
#include "analyzer-decls.h" |
| 10 |
|
| 11 |
int test_connect (int sockfd, const struct sockaddr *addr, |
| 12 |
socklen_t addrlen) |
| 13 |
{ |
| 14 |
return connect (sockfd, addr, addrlen); |
| 15 |
} |
| 16 |
|
| 17 |
void test_null_connect (int fd) |
| 18 |
{ |
| 19 |
errno = 0; |
| 20 |
int result = connect (fd, NULL, 0); |
| 21 |
__analyzer_eval (result == -1); /* { dg-warning "TRUE" } */ |
| 22 |
__analyzer_eval (errno > 0); /* { dg-warning "TRUE" } */ |
| 23 |
} |
| 24 |
|
| 25 |
int test_uninit_addr (int fd, const char *sockname) |
| 26 |
{ |
| 27 |
struct sockaddr_un addr; |
| 28 |
return connect (fd, (struct sockaddr *)&addr, sizeof (addr)); |
| 29 |
// TODO: complain about uninit addr. |
| 30 |
} |
| 31 |
|
| 32 |
void test_connect_after_bind (const char *sockname, |
| 33 |
const struct sockaddr *baddr, socklen_t baddrlen, |
| 34 |
const struct sockaddr *caddr, socklen_t caddrlen) |
| 35 |
{ |
| 36 |
int fd = socket (AF_UNIX, SOCK_STREAM, 0); /* { dg-message "stream socket created here" } */ |
| 37 |
if (fd == -1) |
| 38 |
return; |
| 39 |
|
| 40 |
if (bind (fd, baddr, baddrlen) == -1) |
| 41 |
{ |
| 42 |
close (fd); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
connect (fd, caddr, caddrlen); /* { dg-warning "'connect' on file descriptor 'fd' in wrong phase" "warning" } */ |
| 47 |
/* { dg-message "'connect' expects a new socket file descriptor but 'fd' is bound" "final event" { target *-*-* } .-1 } */ |
| 48 |
|
| 49 |
close (fd); |
| 50 |
} |
| 51 |
|
| 52 |
int test_connect_on_constant () |
| 53 |
{ |
| 54 |
return connect (0, NULL, 0); |
| 55 |
} |