1 // Test that ASan doesn't raise false alarm when MSG_TRUNC is present.
2 //
3 // RUN: %clangxx %s -o %t && %run %t 2>&1
4 //
5 // UNSUPPORTED: android
6 
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <netinet/ip.h>
12 #include <assert.h>
13 
main()14 int main() {
15   int fd_0 = socket(AF_INET, SOCK_DGRAM, 0);
16   int fd_1 = socket(AF_INET, SOCK_DGRAM, 0);
17   struct sockaddr_in sin;
18   socklen_t len = sizeof(sin);
19   char *buf = (char *)malloc(1);
20 
21   sin.sin_family = AF_INET;
22   // Choose a random port to bind.
23   sin.sin_port = 0;
24   sin.sin_addr.s_addr = INADDR_ANY;
25 
26   assert(bind(fd_1, (struct sockaddr *)&sin, sizeof(sin)) == 0);
27   // Get the address and port binded.
28   assert(getsockname(fd_1, (struct sockaddr *)&sin, &len) == 0);
29   assert(sendto(fd_0, "hello", strlen("hello"), MSG_DONTWAIT,
30                 (struct sockaddr *)&sin, sizeof(sin)) != -1);
31   assert(recv(fd_1, buf, 1, MSG_TRUNC) != -1);
32   free(buf);
33 
34   return 0;
35 }
36 
37