| 1 |
// RUN: %clang %s -o %t && %run %t |
| 2 |
// Verify that even if iconv returned -1 |
| 3 |
// we still treat the initialized part of outbuf as properly initialized. |
| 4 |
|
| 5 |
// UNSUPPORTED: android |
| 6 |
|
| 7 |
#include <iconv.h> |
| 8 |
#include <assert.h> |
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
int main() { |
| 12 |
iconv_t cd = iconv_open("UTF-8", "no"); |
| 13 |
assert(cd != (iconv_t)-1); |
| 14 |
char in[11] = {0x7e, 0x7e, 0x5f, 0x53, 0x55, 0x3e, |
| 15 |
0x99, 0x3c, 0x7e, 0x7e, 0x7e}; |
| 16 |
fprintf(stderr, "cd: %p\n", (void*)cd); |
| 17 |
char out[100]; |
| 18 |
char *inbuf = &in[0]; |
| 19 |
size_t inbytesleft = 11; |
| 20 |
char *outbuf = &out[0]; |
| 21 |
size_t outbytesleft = 100; |
| 22 |
int ret = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); |
| 23 |
assert(ret == -1); |
| 24 |
assert(outbuf - &out[0] == 10); |
| 25 |
for (int i = 0; i < 10; i++) { |
| 26 |
if (out[i] == 0x77) return 1; |
| 27 |
fprintf(stderr, "OUT%d 0x%x -- OK\n", i, (unsigned char)out[i]); |
| 28 |
} |
| 29 |
iconv_close(cd); |
| 30 |
} |
| 31 |
|