Commit b25265c5e4bc2de52dd67a634c5c4567bb62d70d

Alexei Podtelezhnikov 2012-02-29T13:45:24

Avoid modulo operators against a power-of-two denominator. * src/afcjk.c (af_hint_normal_stem), src/base/ftoutln.c (ft_contour_has), src/cff/cffgload.c (cff_decoder_parse_charstrings) <cff_op_vvcurveto, cff_op_hhcurveto, cff_op_hvcurveto>, src/gxvalid/gxvcommn.c (GXV_32BIT_ALIGNMENT_VALIDATE), src/gxvalid/gxvfeat.c (gxv_feat_setting_validate): Replace `%' with `&' operator.

diff --git a/ChangeLog b/ChangeLog
index 2d89d12..9fb0b92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-02-29  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	Avoid modulo operators against a power-of-two denominator.
+
+	* src/afcjk.c (af_hint_normal_stem), src/base/ftoutln.c
+	(ft_contour_has), src/cff/cffgload.c (cff_decoder_parse_charstrings)
+	<cff_op_vvcurveto, cff_op_hhcurveto, cff_op_hvcurveto>,
+	src/gxvalid/gxvcommn.c (GXV_32BIT_ALIGNMENT_VALIDATE),
+	src/gxvalid/gxvfeat.c (gxv_feat_setting_validate): Replace `%' with
+	`&' operator.
+
 2012-02-29  Werner Lemberg  <wl@gnu.org>
 
 	[autofit] Don't synchronize digit widths for light rendering mode.
diff --git a/src/autofit/afcjk.c b/src/autofit/afcjk.c
index e45bdba..8e407c8 100644
--- a/src/autofit/afcjk.c
+++ b/src/autofit/afcjk.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Auto-fitter hinting routines for CJK script (body).                  */
 /*                                                                         */
-/*  Copyright 2006-2011 by                                                 */
+/*  Copyright 2006-2012 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -1610,7 +1610,7 @@
         goto Exit;
     }
 
-    offset = cur_len % 64;
+    offset = cur_len & 63;
 
     if ( offset < 32 )
     {
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index 356b156..9ae276d 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType outline management (body).                                  */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 by */
+/*  Copyright 1996-2008, 2010, 2012 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -771,7 +771,7 @@
         return 1;
     }
 
-    return ( n % 2 );
+    return n & 1;
   }
 
 
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index f013425..84847fd 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    OpenType Glyph Loader (body).                                        */
 /*                                                                         */
-/*  Copyright 1996-2011 by                                                 */
+/*  Copyright 1996-2012 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -1513,11 +1513,9 @@
               goto Stack_Underflow;
 
             /* if num_args isn't of the form 4n or 4n+1, */
-            /* we reduce it to 4n+1                      */
+            /* we enforce it by clearing the second bit  */
 
-            nargs = num_args - num_args % 4;
-            if ( num_args - nargs > 0 )
-              nargs += 1;
+            nargs = num_args & ~2;
 
             if ( cff_builder_start_point( builder, x, y ) )
               goto Fail;
@@ -1560,11 +1558,9 @@
               goto Stack_Underflow;
 
             /* if num_args isn't of the form 4n or 4n+1, */
-            /* we reduce it to 4n+1                      */
+            /* we enforce it by clearing the second bit  */
 
-            nargs = num_args - num_args % 4;
-            if ( num_args - nargs > 0 )
-              nargs += 1;
+            nargs = num_args & ~2;
 
             if ( cff_builder_start_point( builder, x, y ) )
               goto Fail;
@@ -1612,11 +1608,9 @@
               goto Stack_Underflow;
 
             /* if num_args isn't of the form 8n, 8n+1, 8n+4, or 8n+5, */
-            /* we reduce it to the largest one which fits             */
+            /* we enforce it by clearing the second bit               */
 
-            nargs = num_args - num_args % 4;
-            if ( num_args - nargs > 0 )
-              nargs += 1;
+            nargs = num_args & ~2;
 
             args -= nargs;
             if ( check_points( builder, ( nargs / 4 ) * 3 ) )
diff --git a/src/gxvalid/gxvcommn.h b/src/gxvalid/gxvcommn.h
index 35c043d..1ff87e4 100644
--- a/src/gxvalid/gxvcommn.h
+++ b/src/gxvalid/gxvcommn.h
@@ -4,7 +4,8 @@
 /*                                                                         */
 /*    TrueTypeGX/AAT common tables validation (specification).             */
 /*                                                                         */
-/*  Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
+/*  Copyright 2004, 2005, 2012                                             */
+/*  by suzuki toshiya, Masatake YAMATO, Red Hat K.K.,                      */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -316,7 +317,7 @@ FT_BEGIN_HEADER
 #define GXV_32BIT_ALIGNMENT_VALIDATE( a ) \
           FT_BEGIN_STMNT                  \
             {                             \
-              if ( 0 != ( (a) % 4 ) )     \
+              if ( (a) & 3 )              \
                 FT_INVALID_OFFSET ;       \
             }                             \
           FT_END_STMNT
diff --git a/src/gxvalid/gxvfeat.c b/src/gxvalid/gxvfeat.c
index 46792bb..6f75650 100644
--- a/src/gxvalid/gxvfeat.c
+++ b/src/gxvalid/gxvfeat.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    TrueTypeGX/AAT feat table validation (body).                         */
 /*                                                                         */
-/*  Copyright 2004, 2005, 2008 by                                          */
+/*  Copyright 2004, 2005, 2008, 2012 by                                    */
 /*  suzuki toshiya, Masatake YAMATO, Red Hat K.K.,                         */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
@@ -176,7 +176,7 @@
     setting = FT_NEXT_USHORT( p );
 
     /* If we have exclusive setting, the setting should be odd. */
-    if ( exclusive && ( setting % 2 ) == 0 )
+    if ( exclusive && ( setting & 1 ) == 0 )
       FT_INVALID_DATA;
 
     gxv_feat_name_index_validate( p, limit, valid );