1 // RUN: %clangxx_msan -g -O0 %s -o %t && \
2 // RUN:     %run %t 2>&1
3 // RUN: %clangxx_msan -g -O0 -DUNINIT=1 %s -o %t && \
4 // RUN:     not %run %t 2>&1 | FileCheck %s
5 
6 #include <assert.h>
7 #include <string.h>
8 #include <rpc/xdr.h>
9 
10 #include <sanitizer/msan_interface.h>
11 
main(int argc,char * argv[])12 int main(int argc, char *argv[]) {
13   XDR xdrs;
14   char buf[100];
15   xdrmem_create(&xdrs, buf, sizeof(buf), XDR_ENCODE);
16   char s[20];
17 #ifndef UNINIT
18   strcpy(s, "hello");
19 #endif
20   char *sp = s;
21   bool_t res = xdr_string(&xdrs, &sp, sizeof(s));
22   // CHECK: MemorySanitizer: use-of-uninitialized-value
23   // CHECK: {{in main.*sunrpc_string.cc:}}[[@LINE-2]]
24   assert(res == TRUE);
25   xdr_destroy(&xdrs);
26 
27   xdrmem_create(&xdrs, buf, sizeof(buf), XDR_DECODE);
28   char s2[20];
29   char *sp2 = s2;
30   res = xdr_string(&xdrs, &sp2, sizeof(s2));
31   assert(res == TRUE);
32   assert(strcmp(s, s2) == 0);
33   xdr_destroy(&xdrs);
34   return 0;
35 }
36