Don't fail when reading an empty script.
authorEric Mader <emader@src.gnome.org>
Fri, 6 Sep 2002 22:45:23 +0000 (22:45 +0000)
committerEric Mader <emader@src.gnome.org>
Fri, 6 Sep 2002 22:45:23 +0000 (22:45 +0000)
src/ftxopen.c
src/ftxopen.h

index 3101d6f..a072daf 100644 (file)
 
     if ( s->LangSysCount == 0 && s->DefaultLangSys.FeatureCount == 0 )
     {
-      error = TTO_Err_Invalid_SubTable;
+      error = TTO_Err_Empty_Script;
       goto Fail2;
     }
 
     FT_Error   error;
     FT_Memory  memory = stream->memory;
 
-    FT_UShort          n, m, count;
+    FT_UShort          n, script_count;
     FT_ULong           cur_offset, new_offset, base_offset;
 
     TTO_ScriptRecord*  sr;
     if ( ACCESS_Frame( 2L ) )
       return error;
 
-    count = sl->ScriptCount = GET_UShort();
+    script_count = GET_UShort();
 
     FORGET_Frame();
 
     sl->ScriptRecord = NULL;
 
-    if ( ALLOC_ARRAY( sl->ScriptRecord, count, TTO_ScriptRecord ) )
+    if ( ALLOC_ARRAY( sl->ScriptRecord, script_count, TTO_ScriptRecord ) )
       return error;
 
     sr = sl->ScriptRecord;
 
-    for ( n = 0; n < count; n++ )
+    sl->ScriptCount= 0;
+    for ( n = 0; n < script_count; n++ )
     {
       if ( ACCESS_Frame( 6L ) )
         goto Fail;
 
-      sr[n].ScriptTag = GET_ULong();
+      sr[sl->ScriptCount].ScriptTag = GET_ULong();
       new_offset = GET_UShort() + base_offset;
 
       FORGET_Frame();
 
       cur_offset = FILE_Pos();
-      if ( FILE_Seek( new_offset ) ||
-           ( error = Load_Script( &sr[n].Script, stream ) ) != TT_Err_Ok )
-        goto Fail;
+
+      if ( FILE_Seek( new_offset ) )
+       goto Fail;
+
+      error = Load_Script( &sr[sl->ScriptCount].Script, stream );
+      if ( error == TT_Err_Ok )
+       sl->ScriptCount += 1;
+      else if ( error != TTO_Err_Empty_Script )
+       goto Fail;
+
       (void)FILE_Seek( cur_offset );
     }
 
+    if ( sl->ScriptCount == 0 )
+    {
+      error = TTO_Err_Invalid_SubTable;
+      goto Fail;
+    }
+    
     return TT_Err_Ok;
 
   Fail:
-    for ( m = 0; m < n; m++ )
-      Free_Script( &sr[m].Script, memory );
+    for ( n = 0; n < sl->ScriptCount; n++ )
+      Free_Script( &sr[n].Script, memory );
 
     FREE( sl->ScriptRecord );
     return error;
index 28dff90..052f25c 100644 (file)
@@ -38,6 +38,7 @@ extern "C" {
 #define TTO_Err_Not_Covered               0x1002
 #define TTO_Err_Too_Many_Nested_Contexts  0x1003
 #define TTO_Err_No_MM_Interpreter         0x1004
+#define TTO_Err_Empty_Script              0x1005
 
 
   /* Script list related structures */