@@ -798,33 +798,36 @@ void ttfont_sfnts(TTStreamWriter& stream, struct TTFONT *font)
798
798
** Find the tables we want and store there vital
799
799
** statistics in tables[].
800
800
*/
801
- for (x=0 ; x < 9 ; x++ )
802
- {
803
- do
804
- {
805
- diff = strncmp ( (char *)ptr, table_names[x], 4 );
806
-
807
- if ( diff > 0 ) /* If we are past it. */
808
- {
809
- tables[x].length = 0 ;
810
- diff = 0 ;
811
- }
812
- else if ( diff < 0 ) /* If we haven't hit it yet. */
813
- {
814
- ptr += 16 ;
815
- }
816
- else if ( diff == 0 ) /* Here it is! */
817
- {
818
- tables[x].newoffset = nextoffset;
819
- tables[x].checksum = getULONG ( ptr + 4 );
820
- tables[x].oldoffset = getULONG ( ptr + 8 );
821
- tables[x].length = getULONG ( ptr + 12 );
822
- nextoffset += ( ((tables[x].length + 3 ) / 4 ) * 4 );
823
- count++;
824
- ptr += 16 ;
825
- }
826
- }
827
- while (diff != 0 );
801
+ ULONG num_tables_read = 0 ; /* Number of tables read from the directory */
802
+ for (x = 0 ; x < 9 ; x++) {
803
+ do {
804
+ if (num_tables_read < font->numTables ) {
805
+ /* There are still tables to read from ptr */
806
+ diff = strncmp ((char *)ptr, table_names[x], 4 );
807
+
808
+ if (diff > 0 ) { /* If we are past it. */
809
+ tables[x].length = 0 ;
810
+ diff = 0 ;
811
+ } else if (diff < 0 ) { /* If we haven't hit it yet. */
812
+ ptr += 16 ;
813
+ num_tables_read++;
814
+ } else if (diff == 0 ) { /* Here it is! */
815
+ tables[x].newoffset = nextoffset;
816
+ tables[x].checksum = getULONG ( ptr + 4 );
817
+ tables[x].oldoffset = getULONG ( ptr + 8 );
818
+ tables[x].length = getULONG ( ptr + 12 );
819
+ nextoffset += ( ((tables[x].length + 3 ) / 4 ) * 4 );
820
+ count++;
821
+ ptr += 16 ;
822
+ num_tables_read++;
823
+ }
824
+ } else {
825
+ /* We've read the whole table directory already */
826
+ /* Some tables couldn't be found */
827
+ tables[x].length = 0 ;
828
+ break ; /* Proceed to next tables[x] */
829
+ }
830
+ } while (diff != 0 );
828
831
829
832
} /* end of for loop which passes over the table directory */
830
833
0 commit comments