shithub: freetype+ttf2subf

Download patch

ref: f24dbb28118170bc9d7f71e73eedc00d3bc855bf
parent: 86e7385342b11ac6a2a179a80585d629e97f2a1f
author: Alexei Podtelezhnikov <[email protected]>
date: Mon Aug 6 00:58:18 EDT 2018

[pcf] Use unsigned types.

* src/pcf/pcf.h (PCF_Encoding): Use unsigned `enc'.
* src/pcf/pcfdrivr.c (pcf_cmap_char_{index,next}): Ditto.
* src/pcf/pcfread.c (pcf_get_encodings): Use unsigned types.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-08-06  Alexei Podtelezhnikov  <[email protected]>
+
+	[pcf] Use unsigned types.
+
+	* src/pcf/pcf.h (PCF_Encoding): Use unsigned `enc'.
+	* src/pcf/pcfdrivr.c (pcf_cmap_char_{index,next}): Ditto.
+	* src/pcf/pcfread.c (pcf_get_encodings): Use unsigned types.
+
 2018-08-05  Werner Lemberg  <[email protected]>
 
 	* src/truetype/ttgload.c (compute_glyph_metrics): Fix overflow.
--- a/src/pcf/pcf.h
+++ b/src/pcf/pcf.h
@@ -130,7 +130,7 @@
    */
   typedef struct  PCF_EncodingRec_
   {
-    FT_Long    enc;
+    FT_ULong   enc;
     FT_UShort  glyph;  /* an index into PCF_Face's `metrics' array */
 
   } PCF_EncodingRec, *PCF_Encoding;
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -123,7 +123,7 @@
 
 
       mid  = ( min + max ) >> 1;
-      code = (FT_ULong)encodings[mid].enc;
+      code = encodings[mid].enc;
 
       if ( charcode == code )
       {
@@ -161,7 +161,7 @@
 
 
       mid  = ( min + max ) >> 1;
-      code = (FT_ULong)encodings[mid].enc;
+      code = encodings[mid].enc;
 
       if ( charcode == code )
       {
@@ -178,7 +178,7 @@
     charcode = 0;
     if ( min < cmap->num_encodings )
     {
-      charcode = (FT_ULong)encodings[min].enc;
+      charcode = encodings[min].enc;
       result   = encodings[min].glyph;
     }
 
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -944,12 +944,12 @@
     FT_Error      error;
     FT_Memory     memory = FT_FACE( face )->memory;
     FT_ULong      format, size;
-    FT_Short      firstCol, lastCol;
-    FT_Short      firstRow, lastRow;
+    FT_UShort     firstCol, lastCol;
+    FT_UShort     firstRow, lastRow;
     FT_ULong      nencoding;
     FT_UShort     defaultCharRow, defaultCharCol;
     FT_UShort     encodingOffset, defaultCharEncodingOffset;
-    FT_Short      i, j;
+    FT_UShort     i, j;
     FT_Byte*      pos;
     FT_ULong      k;
     PCF_Encoding  encoding = NULL;
@@ -975,18 +975,18 @@
     /* make sense for most encodings.                         */
     if ( PCF_BYTE_ORDER( format ) == MSBFirst )
     {
-      firstCol          = FT_GET_SHORT();
-      lastCol           = FT_GET_SHORT();
-      firstRow          = FT_GET_SHORT();
-      lastRow           = FT_GET_SHORT();
+      firstCol          = FT_GET_USHORT();
+      lastCol           = FT_GET_USHORT();
+      firstRow          = FT_GET_USHORT();
+      lastRow           = FT_GET_USHORT();
       face->defaultChar = FT_GET_USHORT();
     }
     else
     {
-      firstCol          = FT_GET_SHORT_LE();
-      lastCol           = FT_GET_SHORT_LE();
-      firstRow          = FT_GET_SHORT_LE();
-      lastRow           = FT_GET_SHORT_LE();
+      firstCol          = FT_GET_USHORT_LE();
+      lastCol           = FT_GET_USHORT_LE();
+      firstRow          = FT_GET_USHORT_LE();
+      lastRow           = FT_GET_USHORT_LE();
       face->defaultChar = FT_GET_USHORT_LE();
     }
 
@@ -1008,10 +1008,8 @@
                 face->defaultChar ));
 
     /* sanity checks; we limit numbers of rows and columns to 256 */
-    if ( firstCol < 0       ||
-         firstCol > lastCol ||
+    if ( firstCol > lastCol ||
          lastCol  > 0xFF    ||
-         firstRow < 0       ||
          firstRow > lastRow ||
          lastRow  > 0xFF    )
       return FT_THROW( Invalid_Table );
@@ -1032,14 +1030,14 @@
     defaultCharCol = face->defaultChar & 0xFF;
 
     /* validate default character */
-    if ( defaultCharRow < (FT_UShort)firstRow ||
-         defaultCharRow > (FT_UShort)lastRow  ||
-         defaultCharCol < (FT_UShort)firstCol ||
-         defaultCharCol > (FT_UShort)lastCol  )
+    if ( defaultCharRow < firstRow ||
+         defaultCharRow > lastRow  ||
+         defaultCharCol < firstCol ||
+         defaultCharCol > lastCol  )
     {
-      face->defaultChar = (FT_UShort)firstRow * 256U + (FT_UShort)firstCol;
+      face->defaultChar = firstRow * 256U + firstCol;
       FT_TRACE0(( "pcf_get_encodings:"
-                  " Invalid default character set to %d\n",
+                  " Invalid default character set to %u\n",
                   face->defaultChar ));
 
       defaultCharRow = face->defaultChar >> 8;
@@ -1054,9 +1052,8 @@
     /* `stream->cursor' still points at the beginning of the frame; */
     /* we can thus easily get the offset to the default character   */
     pos = stream->cursor +
-            2 * ( ( defaultCharRow - (FT_UShort)firstRow ) *
-                    ( lastCol - firstCol + 1 ) +
-                  defaultCharCol - (FT_UShort)firstCol );
+            2 * ( ( defaultCharRow - firstRow ) * ( lastCol - firstCol + 1 ) +
+                  defaultCharCol - firstCol );
 
     if ( PCF_BYTE_ORDER( format ) == MSBFirst )
       defaultCharEncodingOffset = FT_PEEK_USHORT( pos );
@@ -1102,10 +1099,10 @@
           else if ( encodingOffset == 0 )
             encodingOffset = defaultCharEncodingOffset;
 
-          encoding[k].enc   = i * 256 + j;
+          encoding[k].enc   = i * 256U + j;
           encoding[k].glyph = encodingOffset;
 
-          FT_TRACE5(( "  code %d (0x%04X): idx %d\n",
+          FT_TRACE5(( "  code %u (0x%04X): idx %u\n",
                       encoding[k].enc, encoding[k].enc, encoding[k].glyph ));
 
           k++;