Use '%z' instead of '%Z' on printf functions
[glibc.git] / iconvdata / bug-iconv15.c
blob9d12a8d3a2ef2c52fd0115e668cf268153bf39ee
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.
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.
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.
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/>. */
20 #include <stddef.h>
21 #include <iconv.h>
22 #include <support/check.h>
24 static int
25 do_test (void)
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;
35 cd = iconv_open ("UTF8", "ISO-2022-JP-3");
36 TEST_VERIFY_EXIT (cd != (iconv_t) -1);
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);
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));
48 /* Second call shall emit spurious NUL character in unpatched glibc. */
49 TEST_VERIFY (iconv (cd, NULL, NULL, &outbuf, &outleft) != (size_t) -1);
51 /* No characters are expected to be produced. */
52 TEST_VERIFY (outbuf == out);
53 TEST_VERIFY (outleft == sizeof (out));
55 TEST_VERIFY_EXIT (iconv_close (cd) != -1);
57 return 0;
60 #include <support/test-driver.c>