freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 69414e7: * src/cff/cffparse.c (cff_parse_num): Simpli


From: Werner LEMBERG
Subject: [freetype2] master 69414e7: * src/cff/cffparse.c (cff_parse_num): Simplify.
Date: Tue, 3 Jan 2017 05:54:21 +0000 (UTC)

branch: master
commit 69414e7afd41e18f82190c32670dc1784676be9c
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    * src/cff/cffparse.c (cff_parse_num): Simplify.
---
 ChangeLog          |    8 ++++++--
 src/cff/cffparse.c |   20 ++++++++++++++------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c13c48e..fef7c1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,13 +1,17 @@
 2017-01-03  Werner Lemberg  <address@hidden>
 
+       * src/cff/cffparse.c (cff_parse_num): Simplify.
+
+2017-01-03  Werner Lemberg  <address@hidden>
+
        Various fixes for clang's undefined behaviour sanitizer.
 
        * src/cff/cffload.c (FT_fdot14ToFixed): Fix casting.
        (cff_blend_doBlend): Don't left-shift negative numbers.
        Handle 5-byte numbers byte by byte to avoid alignment issues.
 
-       * src/cff/cffparse.c (cff_parse): Handle 5-byte numbers byte by byte
-       to avoid alignment issues.
+       * src/cff/cffparse.c (cff_parse_num): Handle 5-byte numbers byte by
+       byte to avoid alignment issues.
 
        * src/cid/cidload (cid_read_subrs): Do nothing if we don't have any
        subrs.
diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c
index 3c701e0..e4ba8fd 100644
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -448,13 +448,21 @@
       /* 16.16 fixed point is used internally for CFF2 blend results. */
       /* Since these are trusted values, a limit check is not needed. */
 
-      /* After the 255, 4 bytes give the number. */
-      /* Blend result is rounded to integer.     */
+      /* After the 255, 4 bytes give the number.                 */
+      /* The blend value is converted to integer, with rounding; */
+      /* due to the right-shift we don't need the lowest byte.   */
+#if 0
+      return (FT_Short)(
+               ( ( ( (FT_UInt32)*( d[0] + 1 ) << 24 ) |
+                   ( (FT_UInt32)*( d[0] + 2 ) << 16 ) |
+                   ( (FT_UInt32)*( d[0] + 3 ) <<  8 ) |
+                     (FT_UInt32)*( d[0] + 4 )         ) + 0x8000U ) >> 16 );
+#else
       return (FT_Short)(
-               ( ( ( (FT_ULong)*( d[0] + 1 ) << 24 ) |
-                   ( (FT_ULong)*( d[0] + 2 ) << 16 ) |
-                   ( (FT_ULong)*( d[0] + 3 ) <<  8 ) |
-                     (FT_ULong)*( d[0] + 4 )         ) + 0x8000U ) >> 16 );
+               ( ( ( (FT_UInt32)*( d[0] + 1 ) << 16 ) |
+                   ( (FT_UInt32)*( d[0] + 2 ) <<  8 ) |
+                     (FT_UInt32)*( d[0] + 3 )         ) + 0x80U ) >> 8 );
+#endif
     }
 
     else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]