| Alexey Samsonov | d06aa3d | 2015-03-02 19:34:27 +0000 | [diff] [blame] | 1 | // RUN: %clangxx_msan -g -O0 %s -o %t && \ |
| Greg Fitzgerald | b8aae54 | 2014-04-30 21:34:17 +0000 | [diff] [blame] | 2 | // RUN: %run %t 2>&1 |
| Alexey Samsonov | d06aa3d | 2015-03-02 19:34:27 +0000 | [diff] [blame] | 3 | // RUN: %clangxx_msan -g -O0 -DUNINIT=1 %s -o %t && \ |
| Greg Fitzgerald | b8aae54 | 2014-04-30 21:34:17 +0000 | [diff] [blame] | 4 | // RUN: not %run %t 2>&1 | FileCheck %s |
| Evgeniy Stepanov | 24c8d92 | 2014-04-04 14:51:23 +0000 | [diff] [blame] | 5 | |
| Evgeniy Stepanov | 24c8d92 | 2014-04-04 14:51:23 +0000 | [diff] [blame] | 6 | #include <assert.h> |
| 7 | #include <string.h> |
| 8 | #include <rpc/xdr.h> |
| 9 | |
| 10 | #include <sanitizer/msan_interface.h> |
| 11 | |
| 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 | unsigned sz = 6; |
| 22 | bool_t res = xdr_bytes(&xdrs, &sp, &sz, sizeof(s)); |
| 23 | // CHECK: MemorySanitizer: use-of-uninitialized-value |
| 24 | // CHECK: {{in main.*sunrpc_bytes.cc:}}[[@LINE-2]] |
| 25 | assert(res == TRUE); |
| 26 | xdr_destroy(&xdrs); |
| 27 | |
| 28 | xdrmem_create(&xdrs, buf, sizeof(buf), XDR_DECODE); |
| 29 | char s2[20]; |
| 30 | char *sp2 = s2; |
| 31 | unsigned sz2; |
| 32 | res = xdr_bytes(&xdrs, &sp2, &sz2, sizeof(s2)); |
| 33 | assert(res == TRUE); |
| 34 | assert(sz == sz2); |
| 35 | assert(strcmp(s, s2) == 0); |
| 36 | xdr_destroy(&xdrs); |
| 37 | return 0; |
| 38 | } |