1 // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2 // RUN: %clangxx_msan -O3 -g %s -o %t && %run %t
3
4 // RUN: %clangxx_msan -DPOSITIVE -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
5 // RUN: %clangxx_msan -DPOSITIVE -O3 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
6
7 // Reports different report (not analyzed)
8 // XFAIL: netbsd
9
10 #include <assert.h>
11 #include <stdlib.h>
12 #include <net/if.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <sys/ioctl.h>
16 #include <sys/socket.h>
17 #include <unistd.h>
18
main(int argc,char ** argv)19 int main(int argc, char **argv) {
20 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
21
22 struct ifreq ifreqs[20];
23 struct ifconf ifc;
24 ifc.ifc_ifcu.ifcu_req = ifreqs;
25 #ifndef POSITIVE
26 ifc.ifc_len = sizeof(ifreqs);
27 #endif
28 int res = ioctl(fd, SIOCGIFCONF, (void *)&ifc);
29 // CHECK: Uninitialized bytes in ioctl{{.*}} at offset 0 inside [0x{{.*}}, 4)
30 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
31 // CHECK: #{{.*}} in main {{.*}}ioctl_custom.cpp:[[@LINE-3]]
32 assert(res == 0);
33 for (int i = 0; i < ifc.ifc_len / sizeof(*ifc.ifc_ifcu.ifcu_req); ++i)
34 printf("%d %zu %s\n", i, strlen(ifreqs[i].ifr_name), ifreqs[i].ifr_name);
35 return 0;
36 }
37