05191a
--- ttmkfdir-3.0.9.orig/encoding.l	2003-01-08 14:25:25.000000000 +0900
05191a
+++ ttmkfdir-3.0.9/encoding.l	2005-08-03 19:24:22.000000000 +0900
05191a
@@ -21,6 +21,19 @@
05191a
 
05191a
 static Encoding       *cur_enc; 
05191a
 static NumericMapping *cur_map;
05191a
+static int is_created_map = 0;
05191a
+
05191a
+static void
05191a
+create_mapping(void)
05191a
+{
05191a
+    cur_map = new NumericMapping (cur_enc->size,
05191a
+				  TT_PLATFORM_MICROSOFT,
05191a
+				  TT_MS_ID_UNICODE_CS);
05191a
+    
05191a
+    cur_enc->enc_size = 0;
05191a
+    cur_enc->start_code = 0xffff;
05191a
+    is_created_map = 1;
05191a
+}
05191a
 
05191a
 %}
05191a
 
05191a
@@ -67,12 +80,6 @@
05191a
 }
05191a
 
05191a
 <INSIDE_ENC_BLOCK>STARTMAPPING{WHITESPACES}unicode {
05191a
-    cur_map = new NumericMapping (cur_enc->size,
05191a
-				  TT_PLATFORM_MICROSOFT,
05191a
-				  TT_MS_ID_UNICODE_CS);
05191a
-    
05191a
-    cur_enc->enc_size = 0;
05191a
-    cur_enc->start_code = 0xffff;
05191a
     BEGIN(INSIDE_MAP_BLOCK);
05191a
 }
05191a
 
05191a
@@ -107,6 +114,12 @@
05191a
 	i2 = i1;
05191a
     }
05191a
     
05191a
+    /* avoid a crash issue */
05191a
+    if (cur_enc->size < i2)
05191a
+	cur_enc->size = i2;
05191a
+    if (!is_created_map)
05191a
+	create_mapping();
05191a
+
05191a
     /* now mark all the unassigned codes */
05191a
     for (long i = i1; i <= i2; i++) {
05191a
 	(*cur_map)[i] = -1;
05191a
@@ -114,10 +127,14 @@
05191a
 }
05191a
 
05191a
 <INSIDE_MAP_BLOCK>{NUMBER}({WHITESPACES}{NUMBER}){0,2} {
05191a
-    int numbers[3], i = 0, start_range, end_range, target, res;
05191a
+    unsigned int start_range;
05191a
+    int numbers[3], i = 0, end_range, target, res;
05191a
     char *startptr;
05191a
     char *endptr = yytext;
05191a
 
05191a
+    if (!is_created_map)
05191a
+	create_mapping();
05191a
+
05191a
     for (i = 0;;i++) {
05191a
 	startptr = endptr;
05191a
 	res = std::strtol (startptr, &endptr, 0);
05191a
@@ -150,9 +167,14 @@
05191a
 
05191a
 
05191a
 <INSIDE_MAP_BLOCK>ENDMAPPING {
05191a
+    /* it may not happens but to be safe */
05191a
+    if (!is_created_map)
05191a
+	create_mapping();
05191a
+
05191a
     cur_enc->AddMapping (cur_map);
05191a
     dest.insert (std::make_pair(cur_map->cmapkey(), cur_enc));;
05191a
     BEGIN(INSIDE_ENC_BLOCK);
05191a
+    is_created_map = 0;
05191a
 }
05191a
 
05191a
 <INSIDE_UNKNOWN_MAP>ENDMAPPING {