OSDN Git Service

* fix memory violation. mentioned by mame [ruby-dev:36373]
authorNARUSE, Yui <naruse@users.sourceforge.jp>
Fri, 19 Sep 2008 03:40:48 +0000 (03:40 +0000)
committerNARUSE, Yui <naruse@users.sourceforge.jp>
Fri, 19 Sep 2008 03:40:48 +0000 (03:40 +0000)
nkf.c

diff --git a/nkf.c b/nkf.c
index 50e7aa6..8fa9d5b 100644 (file)
--- a/nkf.c
+++ b/nkf.c
@@ -31,7 +31,7 @@
  * \e$B8=:_!"\e(Bnkf \e$B$O\e(B SorceForge \e$B$K$F%a%s%F%J%s%9$,B3$1$i$l$F$$$^$9!#\e(B
  * http://sourceforge.jp/projects/nkf/
  ***********************************************************************/
-#define NKF_IDENT "$Id: nkf.c,v 1.179 2008/07/08 09:34:08 naruse Exp $"
+#define NKF_IDENT "$Id: nkf.c,v 1.180 2008/09/18 18:40:48 naruse Exp $"
 #define NKF_VERSION "2.0.8"
 #define NKF_RELEASE_DATE "2008-02-08"
 #define COPY_RIGHT \
@@ -332,7 +332,6 @@ static char *input_codename = NULL; /* NULL: unestablished, "": BINARY */
 static nkf_encoding *input_encoding = NULL;
 static nkf_encoding *output_encoding = NULL;
 
-static int kanji_convert(FILE *f);
 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
 /* UCS Mapping
  * 0: Shift_JIS, eucJP-ascii
@@ -1473,6 +1472,7 @@ s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
     nkf_char val;
 #endif
     static const char shift_jisx0213_s1a3_table[5][2] ={ { 1, 8}, { 3, 4}, { 5,12}, {13,14}, {15, 0} };
+    if (0xFC < c1) return 1;
 #ifdef SHIFTJIS_CP932
     if (!cp932inv_f && is_ibmext_in_sjis(c2)){
        val = shiftjis_cp932[c2 - CP932_TABLE_BEGIN][c1 - 0x40];
@@ -1483,10 +1483,10 @@ s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
     }
     if (cp932inv_f
        && CP932INV_TABLE_BEGIN <= c2 && c2 <= CP932INV_TABLE_END){
-       nkf_char c = cp932inv[c2 - CP932INV_TABLE_BEGIN][c1 - 0x40];
-       if (c){
-           c2 = c >> 8;
-           c1 = c & 0xff;
+       val = cp932inv[c2 - CP932INV_TABLE_BEGIN][c1 - 0x40];
+       if (val){
+           c2 = val >> 8;
+           c1 = val & 0xff;
        }
     }
 #endif /* SHIFTJIS_CP932 */
@@ -5253,7 +5253,7 @@ kanji_convert(FILE *f)
 {
     nkf_char c1=0, c2=0, c3=0, c4=0;
     int shift_mode = 0; /* 0, 1, 2, 3 */
-    char g2 = 0;
+    int g2 = 0;
     int is_8bit = FALSE;
 
     if (input_encoding && !nkf_enc_asciicompat(input_encoding)) {