From b25265c5e4bc2de52dd67a634c5c4567bb62d70d Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Wed, 29 Feb 2012 13:45:24 +0100 Subject: [PATCH] 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) , src/gxvalid/gxvcommn.c (GXV_32BIT_ALIGNMENT_VALIDATE), src/gxvalid/gxvfeat.c (gxv_feat_setting_validate): Replace `%' with `&' operator. --- ChangeLog | 11 +++++++++++ src/autofit/afcjk.c | 4 ++-- src/base/ftoutln.c | 4 ++-- src/cff/cffgload.c | 20 +++++++------------- src/gxvalid/gxvcommn.h | 5 +++-- src/gxvalid/gxvfeat.c | 4 ++-- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d89d1256..9fb0b92c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2012-02-29 Alexei Podtelezhnikov + + 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) + , + src/gxvalid/gxvcommn.c (GXV_32BIT_ALIGNMENT_VALIDATE), + src/gxvalid/gxvfeat.c (gxv_feat_setting_validate): Replace `%' with + `&' operator. + 2012-02-29 Werner Lemberg [autofit] Don't synchronize digit widths for light rendering mode. diff --git a/src/autofit/afcjk.c b/src/autofit/afcjk.c index e45bdbad3..8e407c86c 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 356b15611..9ae276d08 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 f01342585..84847fda5 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 35c043dbd..1ff87e442 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 46792bbf9..6f7565099 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 );