File: bug-iconv2.c

package info (click to toggle)
glibc 2.24-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 223,412 kB
  • sloc: ansic: 991,967; asm: 261,800; sh: 10,385; makefile: 9,710; cpp: 4,169; python: 3,971; perl: 2,254; awk: 1,753; pascal: 1,521; yacc: 291; sed: 80
file content (47 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (31)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Test case by Akira Higuchi <a@kondara.org>.  */

#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int
main (void)
{
  const char *dummy_codesets[] =
  {
    "ISO_8859-1", "ISO_8859-2", "ISO_8859-3", "ISO_8859-4",
    "ISO_8859-5", "ISO_8859-6", "ISO_8859-7", "ISO_8859-8"
  };
  iconv_t dummy_cd[8], cd_a;
  int i;
  char buffer[1024], *to = buffer;
  char *from = (char *) "foobar";
  size_t to_left = 1024, from_left = 6;

  /* load dummy modules */
  for (i = 0; i < 8; i++)
    if ((dummy_cd[i] = iconv_open (dummy_codesets[i], "UTF8")) == (iconv_t) -1)
      exit (1);

  /* load a module... */
  if ((cd_a = iconv_open ("EUC-JP", "UTF8")) == (iconv_t) -1)
    exit (1);
  /* and close it once. we'll reload this later */
  iconv_close (cd_a);

  /* unload dummy modules */
  for (i = 0; i < 8; i++)
    iconv_close (dummy_cd[i]);

  /* load the module again */
  if ((cd_a = iconv_open ("EUC-JP", "UTF8")) == (iconv_t) -1)
    exit (1);

  puts ("This used to crash");
  printf ("%zd\n", iconv (cd_a, &from, &from_left, &to, &to_left));
  iconv_close (cd_a);

  puts ("works now");

  return 0;
}