summaryrefslogtreecommitdiff
path: root/Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c')
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c79
1 files changed, 57 insertions, 22 deletions
diff --git a/Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c b/Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c
index 6ab503806b2..30f501916a6 100644
--- a/Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c
+++ b/Build/source/libs/freetype2/freetype-src/src/psaux/psobjs.c
@@ -4,7 +4,7 @@
*
* Auxiliary functions for PostScript fonts (body).
*
- * Copyright (C) 1996-2022 by
+ * Copyright (C) 1996-2021 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
@@ -99,31 +99,45 @@
}
+ static void
+ shift_elements( PS_Table table,
+ FT_Byte* old_base )
+ {
+ FT_PtrDist delta = table->block - old_base;
+ FT_Byte** offset = table->elements;
+ FT_Byte** limit = offset + table->max_elems;
+
+
+ for ( ; offset < limit; offset++ )
+ {
+ if ( offset[0] )
+ offset[0] += delta;
+ }
+ }
+
+
static FT_Error
- ps_table_realloc( PS_Table table,
- FT_Offset new_size )
+ reallocate_t1_table( PS_Table table,
+ FT_Offset new_size )
{
FT_Memory memory = table->memory;
FT_Byte* old_base = table->block;
FT_Error error;
- /* (re)allocate the base block */
- if ( FT_REALLOC( table->block, table->capacity, new_size ) )
+ /* allocate new base block */
+ if ( FT_ALLOC( table->block, new_size ) )
+ {
+ table->block = old_base;
return error;
+ }
- /* rebase offsets if necessary */
- if ( old_base && table->block != old_base )
+ /* copy elements and shift offsets */
+ if ( old_base )
{
- FT_Byte** offset = table->elements;
- FT_Byte** limit = offset + table->max_elems;
-
-
- for ( ; offset < limit; offset++ )
- {
- if ( *offset )
- *offset = table->block + ( *offset - old_base );
- }
+ FT_MEM_COPY( table->block, old_base, table->capacity );
+ shift_elements( table, old_base );
+ FT_FREE( old_base );
}
table->capacity = new_size;
@@ -190,7 +204,7 @@
new_size = FT_PAD_CEIL( new_size, 1024 );
}
- error = ps_table_realloc( table, new_size );
+ error = reallocate_t1_table( table, new_size );
if ( error )
return error;
@@ -220,12 +234,32 @@
* @InOut:
* table ::
* The target table.
+ *
+ * @Note:
+ * This function does NOT release the heap's memory block. It is up
+ * to the caller to clean it, or reference it in its own structures.
*/
FT_LOCAL_DEF( void )
ps_table_done( PS_Table table )
{
- /* no problem if shrinking fails */
- ps_table_realloc( table, table->cursor );
+ FT_Memory memory = table->memory;
+ FT_Error error;
+ FT_Byte* old_base = table->block;
+
+
+ /* should never fail, because rec.cursor <= rec.size */
+ if ( !old_base )
+ return;
+
+ if ( FT_QALLOC( table->block, table->cursor ) )
+ return;
+ FT_MEM_COPY( table->block, old_base, table->cursor );
+ shift_elements( table, old_base );
+
+ table->capacity = table->cursor;
+ FT_FREE( old_base );
+
+ FT_UNUSED( error );
}
@@ -1064,6 +1098,7 @@
{
FT_Byte* q = (FT_Byte*)objects[idx] + field->offset;
FT_Long val;
+ FT_String* string = NULL;
skip_spaces( &cur, limit );
@@ -1113,9 +1148,8 @@
case T1_FIELD_TYPE_STRING:
case T1_FIELD_TYPE_KEY:
{
- FT_Memory memory = parser->memory;
- FT_UInt len = (FT_UInt)( limit - cur );
- FT_String* string = NULL;
+ FT_Memory memory = parser->memory;
+ FT_UInt len = (FT_UInt)( limit - cur );
if ( cur >= limit )
@@ -1156,6 +1190,7 @@
FT_TRACE0(( "ps_parser_load_field: overwriting field %s\n",
field->ident ));
FT_FREE( *(FT_String**)q );
+ *(FT_String**)q = NULL;
}
if ( FT_QALLOC( string, len + 1 ) )