* src/base/ftcalc.c (FT_MOVE_SIGN): Enclose assignments.

This commit is contained in:
Alexei Podtelezhnikov 2023-09-24 19:39:10 -04:00
parent cc732ec6d1
commit 73490681a7
1 changed files with 31 additions and 60 deletions

View File

@ -69,13 +69,15 @@
/* transfer sign, leaving a positive number; */ /* transfer sign, leaving a positive number; */
/* we need an unsigned value to safely negate INT_MIN (or LONG_MIN) */ /* we need an unsigned value to safely negate INT_MIN (or LONG_MIN) */
#define FT_MOVE_SIGN( x, x_unsigned, s ) \ #define FT_MOVE_SIGN( utype, x, x_unsigned, s ) \
FT_BEGIN_STMNT \ FT_BEGIN_STMNT \
if ( x < 0 ) \ if ( x < 0 ) \
{ \ { \
x_unsigned = 0U - (x_unsigned); \ x_unsigned = 0U - (utype)x; \
s = -s; \ s = -s; \
} \ } \
else \
x_unsigned = (utype)x; \
FT_END_STMNT FT_END_STMNT
/* The following three functions are available regardless of whether */ /* The following three functions are available regardless of whether */
@ -179,13 +181,9 @@
FT_Long d_; FT_Long d_;
a = (FT_UInt64)a_; FT_MOVE_SIGN( FT_UInt64, a_, a, s );
b = (FT_UInt64)b_; FT_MOVE_SIGN( FT_UInt64, b_, b, s );
c = (FT_UInt64)c_; FT_MOVE_SIGN( FT_UInt64, c_, c, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
FT_MOVE_SIGN( c_, c, s );
d = c > 0 ? ( a * b + ( c >> 1 ) ) / c d = c > 0 ? ( a * b + ( c >> 1 ) ) / c
: 0x7FFFFFFFUL; : 0x7FFFFFFFUL;
@ -208,13 +206,9 @@
FT_Long d_; FT_Long d_;
a = (FT_UInt64)a_; FT_MOVE_SIGN( FT_UInt64, a_, a, s );
b = (FT_UInt64)b_; FT_MOVE_SIGN( FT_UInt64, b_, b, s );
c = (FT_UInt64)c_; FT_MOVE_SIGN( FT_UInt64, c_, c, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
FT_MOVE_SIGN( c_, c, s );
d = c > 0 ? a * b / c d = c > 0 ? a * b / c
: 0x7FFFFFFFUL; : 0x7FFFFFFFUL;
@ -257,11 +251,8 @@
FT_Long q_; FT_Long q_;
a = (FT_UInt64)a_; FT_MOVE_SIGN( FT_UInt64, a_, a, s );
b = (FT_UInt64)b_; FT_MOVE_SIGN( FT_UInt64, b_, b, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
q = b > 0 ? ( ( a << 16 ) + ( b >> 1 ) ) / b q = b > 0 ? ( ( a << 16 ) + ( b >> 1 ) ) / b
: 0x7FFFFFFFUL; : 0x7FFFFFFFUL;
@ -422,13 +413,9 @@
/* XXX: this function does not allow 64-bit arguments */ /* XXX: this function does not allow 64-bit arguments */
a = (FT_UInt32)a_; FT_MOVE_SIGN( FT_UInt32, a_, a, s );
b = (FT_UInt32)b_; FT_MOVE_SIGN( FT_UInt32, b_, b, s );
c = (FT_UInt32)c_; FT_MOVE_SIGN( FT_UInt32, c_, c, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
FT_MOVE_SIGN( c_, c, s );
if ( c == 0 ) if ( c == 0 )
a = 0x7FFFFFFFUL; a = 0x7FFFFFFFUL;
@ -470,13 +457,9 @@
/* XXX: this function does not allow 64-bit arguments */ /* XXX: this function does not allow 64-bit arguments */
a = (FT_UInt32)a_; FT_MOVE_SIGN( FT_UInt32, a_, a, s );
b = (FT_UInt32)b_; FT_MOVE_SIGN( FT_UInt32, b_, b, s );
c = (FT_UInt32)c_; FT_MOVE_SIGN( FT_UInt32, c_, c, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
FT_MOVE_SIGN( c_, c, s );
if ( c == 0 ) if ( c == 0 )
a = 0x7FFFFFFFUL; a = 0x7FFFFFFFUL;
@ -575,11 +558,8 @@
/* XXX: this function does not allow 64-bit arguments */ /* XXX: this function does not allow 64-bit arguments */
a = (FT_UInt32)a_; FT_MOVE_SIGN( FT_UInt32, a_, a, s );
b = (FT_UInt32)b_; FT_MOVE_SIGN( FT_UInt32, b_, b, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
if ( a + ( b >> 8 ) <= 8190UL ) if ( a + ( b >> 8 ) <= 8190UL )
a = ( a * b + 0x8000UL ) >> 16; a = ( a * b + 0x8000UL ) >> 16;
@ -614,11 +594,8 @@
/* XXX: this function does not allow 64-bit arguments */ /* XXX: this function does not allow 64-bit arguments */
a = (FT_UInt32)a_; FT_MOVE_SIGN( FT_UInt32, a_, a, s );
b = (FT_UInt32)b_; FT_MOVE_SIGN( FT_UInt32, b_, b, s );
FT_MOVE_SIGN( a_, a, s );
FT_MOVE_SIGN( b_, b, s );
if ( b == 0 ) if ( b == 0 )
{ {
@ -829,11 +806,8 @@
FT_Int sx = 1, sy = 1, shift; FT_Int sx = 1, sy = 1, shift;
x = (FT_UInt32)x_; FT_MOVE_SIGN( FT_UInt32, x_, x, sx );
y = (FT_UInt32)y_; FT_MOVE_SIGN( FT_UInt32, y_, y, sy );
FT_MOVE_SIGN( x_, x, sx );
FT_MOVE_SIGN( y_, y, sy );
/* trivial cases */ /* trivial cases */
if ( x == 0 ) if ( x == 0 )
@ -1122,11 +1096,8 @@
FT_UInt32 factor; FT_UInt32 factor;
scalar = (FT_UInt32)s[i]; FT_MOVE_SIGN( FT_UInt32, s[i], scalar, sign );
factor = (FT_UInt32)f[i]; FT_MOVE_SIGN( FT_UInt32, f[i], factor, sign );
FT_MOVE_SIGN( s[i], scalar, sign );
FT_MOVE_SIGN( f[i], factor, sign );
ft_multo64( scalar, factor, &multResult ); ft_multo64( scalar, factor, &multResult );