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