blob: 477637af2b6316d9ebffb30aed008469bae9acce [file] [log] [blame]
Alexey Samsonovd06aa3d2015-03-02 19:34:27 +00001// RUN: %clangxx_msan -g -O0 %s -o %t && \
Greg Fitzgeraldb8aae542014-04-30 21:34:17 +00002// RUN: %run %t 2>&1
Alexey Samsonovd06aa3d2015-03-02 19:34:27 +00003// RUN: %clangxx_msan -g -O0 -DUNINIT=1 %s -o %t && \
Greg Fitzgeraldb8aae542014-04-30 21:34:17 +00004// RUN: not %run %t 2>&1 | FileCheck %s
Evgeniy Stepanov24c8d922014-04-04 14:51:23 +00005
Evgeniy Stepanov24c8d922014-04-04 14:51:23 +00006#include <assert.h>
7#include <string.h>
8#include <rpc/xdr.h>
9
10#include <sanitizer/msan_interface.h>
11
12int 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}