shithub: freetype+ttf2subf

Download patch

ref: 09223ef92925ec3ce76670fd09c0d4e03fb18b26
parent: 267c6918d1575c83fc4412e3ffff91ae0b07b823
author: Alexei Podtelezhnikov <[email protected]>
date: Wed Jan 26 06:23:38 EST 2022

[pcf] Delay encoding allocation and avoid its zeroing.

* src/pcf/pcfread.c (pcf_get_encodings): Refactor and use FT_QNEW_ARRAY.

git/fs: mount .git/fs: mount/attach disallowed
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -1034,16 +1034,6 @@
          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 @@
       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 @@
     /* 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++ )
@@ -1130,11 +1130,6 @@
       }
     }
     FT_Stream_ExitFrame( stream );
-
-    return error;
-
-  Exit:
-    FT_FREE( enc->offset );
 
   Bail:
     return error;