1 /* Bug 28524: Conversion from ISO-2022-JP-3 with iconv
2 may emit spurious NUL character on state reset.
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 #include <stddef.h>
21 #include <iconv.h>
22 #include <support/check.h>
23
24 static int
do_test(void)25 do_test (void)
26 {
27 char in[] = "\x1b(I";
28 char *inbuf = in;
29 size_t inleft = sizeof (in) - 1;
30 char out[1];
31 char *outbuf = out;
32 size_t outleft = sizeof (out);
33 iconv_t cd;
34
35 cd = iconv_open ("UTF8", "ISO-2022-JP-3");
36 TEST_VERIFY_EXIT (cd != (iconv_t) -1);
37
38 /* First call to iconv should alter internal state.
39 Now, JISX0201_Kana_set is selected and
40 state value != ASCII_set. */
41 TEST_VERIFY (iconv (cd, &inbuf, &inleft, &outbuf, &outleft) != (size_t) -1);
42
43 /* No bytes should have been added to
44 the output buffer at this point. */
45 TEST_VERIFY (outbuf == out);
46 TEST_VERIFY (outleft == sizeof (out));
47
48 /* Second call shall emit spurious NUL character in unpatched glibc. */
49 TEST_VERIFY (iconv (cd, NULL, NULL, &outbuf, &outleft) != (size_t) -1);
50
51 /* No characters are expected to be produced. */
52 TEST_VERIFY (outbuf == out);
53 TEST_VERIFY (outleft == sizeof (out));
54
55 TEST_VERIFY_EXIT (iconv_close (cd) != -1);
56
57 return 0;
58 }
59
60 #include <support/test-driver.c>
61