Skip to content

Commit

Permalink
[cff] Simplify t2_strings management in the old engine.
Browse files Browse the repository at this point in the history
* src/cff/cffparse.c (cff_parser_run): Allocate the charstring buffers
and the list nodes together so that they can be freed at once.
(finalize_t2_strings): Removed as no longer needed.
(cff_parser_done): Updated.
  • Loading branch information
apodtele committed Mar 20, 2023
1 parent 4f0a55d commit 4d8db13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 58 deletions.
56 changes: 7 additions & 49 deletions src/cff/cffparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,6 @@
}


#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
static void
finalize_t2_strings( FT_Memory memory,
void* data,
void* user )
{
FT_UNUSED( user );

if ( data )
{
CFF_T2_String t2 = (CFF_T2_String)data;


FT_FREE( t2->start );
FT_FREE( data );
}
}
#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */


FT_LOCAL_DEF( void )
cff_parser_done( CFF_Parser parser )
{
Expand All @@ -102,10 +82,7 @@
FT_FREE( parser->stack );

#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
FT_List_Finalize( &parser->t2_strings,
finalize_t2_strings,
memory,
NULL );
FT_List_Finalize( &parser->t2_strings, NULL, memory, NULL );
#endif
}

Expand Down Expand Up @@ -1224,9 +1201,6 @@
FT_ULong charstring_len;

FT_Fixed* stack;
FT_ListNode node;
CFF_T2_String t2;
FT_PtrDist t2_size;
FT_Byte* q;


Expand Down Expand Up @@ -1268,30 +1242,16 @@
/* Now copy the stack data in the temporary decoder object, */
/* converting it back to charstring number representations */
/* (this is ugly, I know). */
if ( FT_NEW( node ) )
goto Exit;

FT_List_Add( &parser->t2_strings, node );

if ( FT_NEW( t2 ) )
goto Exit;

node->data = t2;

/* `5' is the conservative upper bound of required bytes per stack */
/* element. */

t2_size = 5 * ( decoder.top - decoder.stack );

if ( FT_QALLOC( q, t2_size ) )
/* The maximum required size is 5 bytes per stack element. */
if ( FT_QALLOC( q, 2 * sizeof ( FT_ListNode ) +
5 * ( decoder.top - decoder.stack ) ) )
goto Exit;

t2->start = q;
t2->limit = q + t2_size;
FT_List_Add( &parser->t2_strings, (FT_ListNode)q );

stack = decoder.stack;
q += 2 * sizeof ( FT_ListNode );

while ( stack < decoder.top )
for ( stack = decoder.stack; stack < decoder.top; stack++ )
{
FT_Long num = *stack;

Expand Down Expand Up @@ -1332,8 +1292,6 @@
*q++ = (FT_Byte)( num & 0xFF );
}
}

stack++;
}
}
#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
Expand Down
9 changes: 0 additions & 9 deletions src/cff/cffparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ FT_BEGIN_HEADER
FT_END_HEADER


#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
typedef struct CFF_T2_String_
{
FT_Byte* start;
FT_Byte* limit;

} CFF_T2_StringRec, *CFF_T2_String;
#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */

#endif /* CFFPARSE_H_ */


Expand Down

0 comments on commit 4d8db13

Please sign in to comment.