summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2019-09-04 12:07:08 +0900
committerHermet Park <hermetpark@gmail.com>2019-09-04 12:07:09 +0900
commit9e3aabe43b96fd405f987ffc257539d60b52fa39 (patch)
treed2f4950ddf332b615a0565178137cf6c5b7aeea9
parenta2f846bffcecfec7d3d73b0f4994666f5dc930ff (diff)
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
-rw-r--r--src/static_libs/freetype/sw_ft_math.c37
-rw-r--r--src/static_libs/freetype/sw_ft_math.h20
-rw-r--r--src/static_libs/freetype/sw_ft_types.h2
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
41 41
42 42
43 43
44SW_FT_Long 44SW_FT_Int64
45SW_FT_MulFix( SW_FT_Long a, 45SW_FT_MulFix( SW_FT_Int64 a,
46 SW_FT_Long b ) 46 SW_FT_Int64 b )
47{ 47{
48 SW_FT_Int s = 1; 48 SW_FT_Int s = 1;
49 SW_FT_Long c; 49 SW_FT_Int64 c;
50 50
51 51
52 SW_FT_MOVE_SIGN( a, s ); 52 SW_FT_MOVE_SIGN( a, s );
53 SW_FT_MOVE_SIGN( b, s ); 53 SW_FT_MOVE_SIGN( b, s );
54 54
55 c = (SW_FT_Long)( ( (SW_FT_Int64)a * b + 0x8000L ) >> 16 ); 55 c = ( a * b + 0x8000L ) >> 16;
56 56
57 return ( s > 0 ) ? c : -c; 57 return ( s > 0 ) ? c : -c;
58} 58}
59 59
60SW_FT_Long 60SW_FT_Int64
61SW_FT_MulDiv( SW_FT_Long a, 61SW_FT_MulDiv( SW_FT_Int64 a,
62 SW_FT_Long b, 62 SW_FT_Int64 b,
63 SW_FT_Long c ) 63 SW_FT_Int64 c )
64{ 64{
65 SW_FT_Int s = 1; 65 SW_FT_Int s = 1;
66 SW_FT_Long d; 66 SW_FT_Int64 d;
67 67
68 68
69 SW_FT_MOVE_SIGN( a, s ); 69 SW_FT_MOVE_SIGN( a, s );
70 SW_FT_MOVE_SIGN( b, s ); 70 SW_FT_MOVE_SIGN( b, s );
71 SW_FT_MOVE_SIGN( c, s ); 71 SW_FT_MOVE_SIGN( c, s );
72 72
73 d = (SW_FT_Long)( c > 0 ? ( (SW_FT_Int64)a * b + ( c >> 1 ) ) / c 73 d = c > 0 ? ( a * b + ( c >> 1 ) ) / c
74 : 0x7FFFFFFFL ); 74 : 0x7FFFFFFFL;
75 75
76 return ( s > 0 ) ? d : -d; 76 return ( s > 0 ) ? d : -d;
77} 77}
78 78
79SW_FT_Long 79SW_FT_Int64
80SW_FT_DivFix( SW_FT_Long a, 80SW_FT_DivFix( SW_FT_Int64 a,
81 SW_FT_Long b ) 81 SW_FT_Int64 b )
82{ 82{
83 SW_FT_Int s = 1; 83 SW_FT_Int s = 1;
84 SW_FT_Long q; 84 SW_FT_Int64 q;
85
86 85
87 SW_FT_MOVE_SIGN( a, s ); 86 SW_FT_MOVE_SIGN( a, s );
88 SW_FT_MOVE_SIGN( b, s ); 87 SW_FT_MOVE_SIGN( b, s );
89 88
90 q = (SW_FT_Long)( b > 0 ? ( ( (SW_FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b 89 q = b > 0 ? ( ( a << 16 ) + ( b >> 1 ) ) / b
91 : 0x7FFFFFFFL ); 90 : 0x7FFFFFFFL;
92 91
93 return ( s < 0 ? -q : q ); 92 return ( s < 0 ? -q : q );
94} 93}
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 @@
71/* _second_ argument of this function; this can make a great */ 71/* _second_ argument of this function; this can make a great */
72/* difference. */ 72/* difference. */
73/* */ 73/* */
74SW_FT_Long 74SW_FT_Int64
75SW_FT_MulFix( SW_FT_Long a, 75SW_FT_MulFix( SW_FT_Int64 a,
76 SW_FT_Long b ); 76 SW_FT_Int64 b );
77 77
78/*************************************************************************/ 78/*************************************************************************/
79/* */ 79/* */
@@ -98,10 +98,10 @@ SW_FT_MulFix( SW_FT_Long a,
98/* divide by zero; it simply returns `MaxInt' or `MinInt' depending */ 98/* divide by zero; it simply returns `MaxInt' or `MinInt' depending */
99/* on the signs of `a' and `b'. */ 99/* on the signs of `a' and `b'. */
100/* */ 100/* */
101SW_FT_Long 101SW_FT_Int64
102SW_FT_MulDiv( SW_FT_Long a, 102SW_FT_MulDiv( SW_FT_Int64 a,
103 SW_FT_Long b, 103 SW_FT_Int64 b,
104 SW_FT_Long c ); 104 SW_FT_Int64 c );
105 105
106/*************************************************************************/ 106/*************************************************************************/
107/* */ 107/* */
@@ -120,9 +120,9 @@ SW_FT_MulDiv( SW_FT_Long a,
120/* <Return> */ 120/* <Return> */
121/* The result of `(a*0x10000)/b'. */ 121/* The result of `(a*0x10000)/b'. */
122/* */ 122/* */
123SW_FT_Long 123SW_FT_Int64
124SW_FT_DivFix( SW_FT_Long a, 124SW_FT_DivFix( SW_FT_Int64 a,
125 SW_FT_Long b ); 125 SW_FT_Int64 b );
126 126
127 127
128 128
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 @@
10/* This type is used to store 16.16 fixed-point values, like scaling */ 10/* This type is used to store 16.16 fixed-point values, like scaling */
11/* values or matrix coefficients. */ 11/* values or matrix coefficients. */
12/* */ 12/* */
13typedef signed long SW_FT_Fixed; 13typedef signed long long SW_FT_Fixed;
14 14
15 15
16/*************************************************************************/ 16/*************************************************************************/