| Evgeniy Stepanov | 9c1f832 | 2013-11-28 14:14:48 +0000 | [diff] [blame^] | 1 | // RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t |
| 2 | // RUN: %clangxx_msan -m64 -O0 -g -DPOSITIVE %s -o %t && not %t |& FileCheck %s |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <iconv.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | #include <stdio.h> |
| 9 | #include <errno.h> |
| 10 | |
| 11 | int main(void) { |
| 12 | iconv_t cd = iconv_open("ASCII", "ASCII"); |
| 13 | assert(cd != (iconv_t)-1); |
| 14 | |
| 15 | char inbuf_[100]; |
| 16 | strcpy(inbuf_, "sample text"); |
| 17 | char outbuf_[100]; |
| 18 | char *inbuf = inbuf_; |
| 19 | char *outbuf = outbuf_; |
| 20 | size_t inbytesleft = strlen(inbuf_); |
| 21 | size_t outbytesleft = sizeof(outbuf_); |
| 22 | |
| 23 | #ifdef POSITIVE |
| 24 | { |
| 25 | char u; |
| 26 | char *volatile p = &u; |
| 27 | inbuf_[5] = *p; |
| 28 | } |
| 29 | #endif |
| 30 | |
| 31 | size_t res; |
| 32 | res = iconv(cd, 0, 0, 0, 0); |
| 33 | assert(res != (size_t)-1); |
| 34 | |
| 35 | res = iconv(cd, 0, 0, &outbuf, &outbytesleft); |
| 36 | assert(res != (size_t)-1); |
| 37 | |
| 38 | res = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); |
| 39 | // CHECK: MemorySanitizer: use-of-uninitialized-value |
| 40 | // CHECK: #0 {{.*}} in main {{.*}}iconv.cc:[[@LINE-2]] |
| 41 | assert(res != (size_t)-1); |
| 42 | assert(inbytesleft == 0); |
| 43 | |
| 44 | assert(memcmp(inbuf_, outbuf_, strlen(inbuf_)) == 0); |
| 45 | |
| 46 | iconv_close(cd); |
| 47 | return 0; |
| 48 | } |