[pcf] Delay encoding allocation and avoid its zeroing.

* src/pcf/pcfread.c (pcf_get_encodings): Refactor and use FT_QNEW_ARRAY.
This commit is contained in:
Alexei Podtelezhnikov 2022-01-26 11:23:38 -05:00
parent 267c6918d1
commit 09223ef929
1 changed files with 10 additions and 15 deletions

View File

@ -1034,16 +1034,6 @@ THE SOFTWARE.
enc->lastRow > 0xFF )
return FT_THROW( Invalid_Table );
nencoding = (FT_ULong)( enc->lastCol - enc->firstCol + 1 ) *
(FT_ULong)( enc->lastRow - enc->firstRow + 1 );
if ( FT_NEW_ARRAY( enc->offset, nencoding ) )
goto Bail;
error = FT_Stream_EnterFrame( stream, 2 * nencoding );
if ( error )
goto Exit;
FT_TRACE5(( "\n" ));
defaultCharRow = enc->defaultChar >> 8;
@ -1064,6 +1054,13 @@ THE SOFTWARE.
defaultCharCol = enc->firstCol;
}
nencoding = (FT_ULong)( enc->lastCol - enc->firstCol + 1 ) *
(FT_ULong)( enc->lastRow - enc->firstRow + 1 );
error = FT_Stream_EnterFrame( stream, 2 * nencoding );
if ( error )
goto Bail;
/*
* FreeType mandates that glyph index 0 is the `undefined glyph', which
* PCF calls the `default character'. However, FreeType needs glyph
@ -1109,6 +1106,9 @@ THE SOFTWARE.
/* copy metrics of default character to index 0 */
face->metrics[0] = face->metrics[defaultCharEncodingOffset];
if ( FT_QNEW_ARRAY( enc->offset, nencoding ) )
goto Bail;
/* now loop over all values */
offset = enc->offset;
for ( i = enc->firstRow; i <= enc->lastRow; i++ )
@ -1131,11 +1131,6 @@ THE SOFTWARE.
}
FT_Stream_ExitFrame( stream );
return error;
Exit:
FT_FREE( enc->offset );
Bail:
return error;
}