elf: Fix compile error with -DNDEBUG [BZ #18755]
[glibc.git] / iconvdata / bug-iconv13.c
blobd80523b8aa0c2802aabdf32ee00aa372a8a47be3
1 /* bug 24973: Test EUC-KR module
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <iconv.h>
21 #include <stdio.h>
22 #include <support/check.h>
24 static int
25 do_test (void)
27 iconv_t cd = iconv_open ("UTF-8//IGNORE", "EUC-KR");
28 TEST_VERIFY_EXIT (cd != (iconv_t) -1);
30 /* 0xfe (->0x7e : row 94) and 0xc9 (->0x49 : row 41) are user-defined
31 areas, which are not allowed and should be skipped over due to
32 //IGNORE. The trailing 0xfe also is an incomplete sequence, which
33 should be checked first. */
34 char input[4] = { '\xc9', '\xa1', '\0', '\xfe' };
35 char *inptr = input;
36 size_t insize = sizeof (input);
37 char output[4];
38 char *outptr = output;
39 size_t outsize = sizeof (output);
41 /* This used to crash due to buffer overrun. */
42 TEST_VERIFY (iconv (cd, &inptr, &insize, &outptr, &outsize) == (size_t) -1);
43 TEST_VERIFY (errno == EINVAL);
44 /* The conversion should produce one character, the converted null
45 character. */
46 TEST_VERIFY (sizeof (output) - outsize == 1);
48 TEST_VERIFY_EXIT (iconv_close (cd) != -1);
50 return 0;
53 #include <support/test-driver.c>