From 9e3aabe43b96fd405f987ffc257539d60b52fa39 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Wed, 4 Sep 2019 12:07:08 +0900 Subject: [PATCH] freetype: Prevent lose of data when fixed point divide calculation. Summary: In environments that long is 4byte, fixed-point division calculations will cause data loss. fixed-point division need to more space. Therefore, change all long types to long long types. Test Plan: N/A Reviewers: Hermet, kimcinoo, smohanty Reviewed By: Hermet Subscribers: vtorri, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9817 --- src/static_libs/freetype/sw_ft_math.c | 37 +++++++++++++------------- src/static_libs/freetype/sw_ft_math.h | 20 +++++++------- src/static_libs/freetype/sw_ft_types.h | 2 +- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/static_libs/freetype/sw_ft_math.c b/src/static_libs/freetype/sw_ft_math.c index 268c875c28..a5b147f35c 100644 --- a/src/static_libs/freetype/sw_ft_math.c +++ b/src/static_libs/freetype/sw_ft_math.c @@ -41,54 +41,53 @@ SW_FT_END_STMNT -SW_FT_Long -SW_FT_MulFix( SW_FT_Long a, - SW_FT_Long b ) +SW_FT_Int64 +SW_FT_MulFix( SW_FT_Int64 a, + SW_FT_Int64 b ) { SW_FT_Int s = 1; - SW_FT_Long c; + SW_FT_Int64 c; SW_FT_MOVE_SIGN( a, s ); SW_FT_MOVE_SIGN( b, s ); - c = (SW_FT_Long)( ( (SW_FT_Int64)a * b + 0x8000L ) >> 16 ); + c = ( a * b + 0x8000L ) >> 16; return ( s > 0 ) ? c : -c; } -SW_FT_Long -SW_FT_MulDiv( SW_FT_Long a, - SW_FT_Long b, - SW_FT_Long c ) +SW_FT_Int64 +SW_FT_MulDiv( SW_FT_Int64 a, + SW_FT_Int64 b, + SW_FT_Int64 c ) { SW_FT_Int s = 1; - SW_FT_Long d; + SW_FT_Int64 d; SW_FT_MOVE_SIGN( a, s ); SW_FT_MOVE_SIGN( b, s ); SW_FT_MOVE_SIGN( c, s ); - d = (SW_FT_Long)( c > 0 ? ( (SW_FT_Int64)a * b + ( c >> 1 ) ) / c - : 0x7FFFFFFFL ); + d = c > 0 ? ( a * b + ( c >> 1 ) ) / c + : 0x7FFFFFFFL; return ( s > 0 ) ? d : -d; } -SW_FT_Long -SW_FT_DivFix( SW_FT_Long a, - SW_FT_Long b ) +SW_FT_Int64 +SW_FT_DivFix( SW_FT_Int64 a, + SW_FT_Int64 b ) { SW_FT_Int s = 1; - SW_FT_Long q; - + SW_FT_Int64 q; SW_FT_MOVE_SIGN( a, s ); SW_FT_MOVE_SIGN( b, s ); - q = (SW_FT_Long)( b > 0 ? ( ( (SW_FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b - : 0x7FFFFFFFL ); + q = b > 0 ? ( ( a << 16 ) + ( b >> 1 ) ) / b + : 0x7FFFFFFFL; return ( s < 0 ? -q : q ); } diff --git a/src/static_libs/freetype/sw_ft_math.h b/src/static_libs/freetype/sw_ft_math.h index 95a5c4257e..de607efc1c 100644 --- a/src/static_libs/freetype/sw_ft_math.h +++ b/src/static_libs/freetype/sw_ft_math.h @@ -71,9 +71,9 @@ /* _second_ argument of this function; this can make a great */ /* difference. */ /* */ -SW_FT_Long -SW_FT_MulFix( SW_FT_Long a, - SW_FT_Long b ); +SW_FT_Int64 +SW_FT_MulFix( SW_FT_Int64 a, + SW_FT_Int64 b ); /*************************************************************************/ /* */ @@ -98,10 +98,10 @@ SW_FT_MulFix( SW_FT_Long a, /* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ /* on the signs of `a' and `b'. */ /* */ -SW_FT_Long -SW_FT_MulDiv( SW_FT_Long a, - SW_FT_Long b, - SW_FT_Long c ); +SW_FT_Int64 +SW_FT_MulDiv( SW_FT_Int64 a, + SW_FT_Int64 b, + SW_FT_Int64 c ); /*************************************************************************/ /* */ @@ -120,9 +120,9 @@ SW_FT_MulDiv( SW_FT_Long a, /* */ /* The result of `(a*0x10000)/b'. */ /* */ -SW_FT_Long -SW_FT_DivFix( SW_FT_Long a, - SW_FT_Long b ); +SW_FT_Int64 +SW_FT_DivFix( SW_FT_Int64 a, + SW_FT_Int64 b ); diff --git a/src/static_libs/freetype/sw_ft_types.h b/src/static_libs/freetype/sw_ft_types.h index 828103aeab..f1e42d5f68 100644 --- a/src/static_libs/freetype/sw_ft_types.h +++ b/src/static_libs/freetype/sw_ft_types.h @@ -10,7 +10,7 @@ /* This type is used to store 16.16 fixed-point values, like scaling */ /* values or matrix coefficients. */ /* */ -typedef signed long SW_FT_Fixed; +typedef signed long long SW_FT_Fixed; /*************************************************************************/