File: bug-iconv1.c

package info (click to toggle)
glibc 2.19-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 202,472 kB
  • ctags: 140,344
  • sloc: ansic: 969,274; asm: 241,208; sh: 10,047; makefile: 8,467; cpp: 3,595; perl: 2,077; pascal: 1,839; awk: 1,704; yacc: 317; sed: 73
file content (40 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (25)
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
/* Test program by Satoru Takabayashi.  */
#include <errno.h>
#include <iconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char **argv)
{
  const char in[] = "\x41\x42\x43\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa";
                  /* valid eucJP string */
  const char exp[] = "\x41\x42\x43\x82\xa0\x82\xa2\x82\xa4";
  size_t outbufsize = 10;
                  /* 10 is too small to store full result (intentional) */
  size_t inleft, outleft;
  char *in_p = (char *) in;
  char out[outbufsize];
  char *out_p = out;
  iconv_t cd;
  int i;

  inleft = strlen (in);
  outleft = outbufsize;

  cd = iconv_open ("SJIS", "eucJP");
  if (cd == (iconv_t) -1)
    {
      puts ("iconv_open failed");
      exit (1);
    }

  iconv (cd, &in_p, &inleft, &out_p, &outleft); /* this returns E2BIG */
  for (i = 0; i < outbufsize - outleft; ++i)
    printf (" %02x", (unsigned char) out[i]);
  puts ("");
  iconv_close (cd);

  return outbufsize - outleft != 9 || memcmp (out, exp, 9) != 0;
}