[sfnt] Streamline POST format 2.0 handing (cont'd). * src/sfnt/ttpost.c (load_format_20): Co-allocate the string data and their pointers, which makes it easier to handle and free them. (tt_face_free_ps_names): Updated. * include/freetype/internal/tttypes.h (TT_Post_20): Update type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index 3b52192..fee036b 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -803,7 +803,7 @@ FT_BEGIN_HEADER
FT_UShort num_glyphs;
FT_UShort num_names;
FT_UShort* glyph_indices;
- FT_Char** glyph_names;
+ FT_Byte** glyph_names;
} TT_Post_20Rec, *TT_Post_20;
diff --git a/src/sfnt/ttpost.c b/src/sfnt/ttpost.c
index d3ec757..81992b3 100644
--- a/src/sfnt/ttpost.c
+++ b/src/sfnt/ttpost.c
@@ -167,8 +167,7 @@
FT_UShort num_names;
FT_UShort* glyph_indices = NULL;
- FT_Char** name_strings = NULL;
- FT_Byte* strings = NULL;
+ FT_Byte** name_strings = NULL;
if ( FT_READ_USHORT( num_glyphs ) )
@@ -229,13 +228,17 @@
{
FT_UShort n;
FT_ULong p;
+ FT_Byte* strings;
post_len -= (FT_ULong)num_glyphs * 2UL + 2;
- if ( FT_QALLOC( strings, post_len + 1 ) ||
- FT_STREAM_READ( strings, post_len ) ||
- FT_QNEW_ARRAY( name_strings, num_names ) )
+ if ( FT_QALLOC( name_strings, num_names * sizeof ( FT_Byte* ) +
+ post_len + 1 ) )
+ goto Fail;
+
+ strings = (FT_Byte*)( name_strings + num_names );
+ if ( FT_STREAM_READ( strings, post_len ) )
goto Fail;
/* convert from Pascal- to C-strings and set pointers */
@@ -251,7 +254,7 @@
}
strings[p] = 0;
- name_strings[n] = (FT_Char*)strings + p + 1;
+ name_strings[n] = strings + p + 1;
p += len + 1;
}
strings[post_len] = 0;
@@ -259,22 +262,11 @@
/* deal with missing or insufficient string data */
if ( n < num_names )
{
- if ( post_len == 0 )
- {
- /* fake empty string */
- if ( FT_QREALLOC( strings, 1, 2 ) )
- goto Fail;
+ FT_TRACE4(( "load_format_20: %hu PostScript names are truncated\n",
+ num_names - n ));
- post_len = 1;
- strings[post_len] = 0;
- }
-
- FT_ERROR(( "load_format_20:"
- " all entries in post table are already parsed,"
- " using NULL names for gid %d - %d\n",
- n, num_names - 1 ));
for ( ; n < num_names; n++ )
- name_strings[n] = (FT_Char*)strings + post_len;
+ name_strings[n] = strings + post_len;
}
}
@@ -292,7 +284,6 @@
Fail:
FT_FREE( name_strings );
- FT_FREE( strings );
FT_FREE( glyph_indices );
Exit:
@@ -427,9 +418,6 @@
if ( table->num_names )
{
- table->glyph_names[0]--;
- FT_FREE( table->glyph_names[0] );
-
FT_FREE( table->glyph_names );
table->num_names = 0;
}