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
11int main() {
12 iconv_t cd = iconv_open(tocode: "UTF-8", fromcode: "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, format: "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: cd, inbuf: &inbuf, inbytesleft: &inbytesleft, outbuf: &outbuf, outbytesleft: &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, format: "OUT%d 0x%x -- OK\n", i, (unsigned char)out[i]);
28 }
29 iconv_close(cd: cd);
30}
31
32

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/iconv_test.c