[AA] Rename CaptureInfo -> CaptureAnalysis (NFC) (#116842)
[llvm-project.git] / compiler-rt / test / msan / iconv.cpp
blobeeeff9a3b0c87a6de141558fc49dbadbc169b31f
1 // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2 // RUN: %clangxx_msan -O0 -g -DPOSITIVE %s -o %t && not %run %t 2>&1 | FileCheck %s
4 #include <assert.h>
5 #include <iconv.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include <errno.h>
11 #if defined(__NetBSD__)
12 #include <sys/param.h>
13 #if __NetBSD_Prereq__(9,99,17)
14 #define NETBSD_POSIX_ICONV 1
15 #else
16 #define NETBSD_POSIX_ICONV 0
17 #endif
18 #endif
20 int main(void) {
21 iconv_t cd = iconv_open("ASCII", "ASCII");
22 assert(cd != (iconv_t)-1);
24 char inbuf_[100];
25 strcpy(inbuf_, "sample text");
26 char outbuf_[100];
27 #if defined(__NetBSD__) && !NETBSD_POSIX_ICONV
28 // Some OSes expect the 2nd argument of iconv(3) to be of type const char **
29 const char *inbuf = inbuf_;
30 #else
31 char *inbuf = inbuf_;
32 #endif
33 char *outbuf = outbuf_;
34 size_t inbytesleft = strlen(inbuf_);
35 size_t outbytesleft = sizeof(outbuf_);
37 #ifdef POSITIVE
39 char u;
40 char *volatile p = &u;
41 inbuf_[5] = *p;
43 #endif
45 size_t res;
46 res = iconv(cd, 0, 0, 0, 0);
47 assert(res != (size_t)-1);
49 res = iconv(cd, 0, 0, &outbuf, &outbytesleft);
50 assert(res != (size_t)-1);
52 res = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
53 // CHECK: MemorySanitizer: use-of-uninitialized-value
54 // CHECK: #0 {{.*}} in main {{.*}}iconv.cpp:[[@LINE-2]]
55 assert(res != (size_t)-1);
56 assert(inbytesleft == 0);
58 assert(memcmp(inbuf_, outbuf_, strlen(inbuf_)) == 0);
60 iconv_close(cd);
61 return 0;