summaryrefslogtreecommitdiff
path: root/lang/gauche/patches/patch-ba
blob: d4214dc1eb1a233d293287db36429284272a8bbd (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$NetBSD: patch-ba,v 1.2 2002/10/18 08:08:33 wiz Exp $

There is a problem in ext/charconv/jconv.c which may
cause gosh hang, due to the wrong state management.
Specifically, it happens if you specify "iso-2022-jp"
as the output code, instead of "iso2022jp" or "iso2022-jp".

--shiro



*** ext/charconv/jconv.c	17 Jun 2002 05:41:04 -0000	1.9
--- ext/charconv/jconv.c	26 Sep 2002 05:22:59 -0000
***************
*** 1294,1299 ****
--- 1294,1305 ----
  
  /* case (5) */
  #ifdef HAVE_ICONV_H
+ /* NB: although iconv manages states, we need to keep track of whether
+  * we're sure in default status (JIS_ASCII) or not (we use JIS_UNKNOWN for it).
+  * It's because jconv_iconv_reset will be called twice if there is any
+  * reset sequence; the first call should emit the sequence, but the second
+  * call shoudn't.
+  */
  static size_t jconv_iconv(ScmConvInfo *info, const char **iptr, size_t *iroom,
                            char **optr, size_t *oroom)
  {
***************
*** 1302,1307 ****
--- 1308,1314 ----
      fprintf(stderr, "jconv_iconv %s->%s\n", info->fromCode, info->toCode);
  #endif
      r = iconv(info->handle, (char **)iptr, iroom, optr, oroom);
+     info->ostate = JIS_UNKNOWN;
      if (r == (size_t)-1) {
          if (errno == EINVAL) return INPUT_NOT_ENOUGH;
          if (errno == E2BIG)  return OUTPUT_NOT_ENOUGH;
***************
*** 1315,1325 ****
  static size_t jconv_iconv_reset(ScmConvInfo *info, char *optr, size_t oroom)
  {
      size_t oroom_prev = oroom;
!     size_t r = iconv(info->handle, NULL, 0, &optr, &oroom);
      if (r == (size_t)-1) {
          if (errno == E2BIG)  return OUTPUT_NOT_ENOUGH;
          Scm_Panic("jconv_iconv_reset: unknown error number %d\n", errno);
      }
      return oroom_prev - oroom;
  }
  #endif /*HAVE_ICONV_H*/
--- 1322,1335 ----
  static size_t jconv_iconv_reset(ScmConvInfo *info, char *optr, size_t oroom)
  {
      size_t oroom_prev = oroom;
!     size_t r;
!     if (info->ostate == JIS_ASCII) return 0;
!     r = iconv(info->handle, NULL, 0, &optr, &oroom);
      if (r == (size_t)-1) {
          if (errno == E2BIG)  return OUTPUT_NOT_ENOUGH;
          Scm_Panic("jconv_iconv_reset: unknown error number %d\n", errno);
      }
+     info->ostate = JIS_ASCII;
      return oroom_prev - oroom;
  }
  #endif /*HAVE_ICONV_H*/