Commit 96d26926d1f36ce3feb1d16dfa6f0bfdf6297ec6

Werner Lemberg 2017-06-09T20:34:28

Provide more macros for flooring, ceiling, and rounding. These versions don't produce run-time errors due to integer overflow. * include/freetype/internal/ftobjs.h: Include FT_INTERNAL_CALC_H. (FT_PAD_ROUND_LONG, FT_PAD_CEIL_LONG, FT_PIX_ROUND_LONG, FT_PIX_CEIL_LONG): New macros. (FT_PAD_ROUND_INT32, FT_PAD_CEIL_INT32, FT_PIX_ROUND_INT32, FT_PIX_CEIL_INT32): New macros.

diff --git a/ChangeLog b/ChangeLog
index cd3786d..494d11f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2017-06-09  Werner Lemberg  <wl@gnu.org>
 
+	Provide more macros for flooring, ceiling, and rounding.
+
+	These versions don't produce run-time errors due to integer
+	overflow.
+
+	* include/freetype/internal/ftobjs.h: Include FT_INTERNAL_CALC_H.
+	(FT_PAD_ROUND_LONG, FT_PAD_CEIL_LONG, FT_PIX_ROUND_LONG,
+	FT_PIX_CEIL_LONG): New macros.
+	(FT_PAD_ROUND_INT32, FT_PAD_CEIL_INT32, FT_PIX_ROUND_INT32,
+	FT_PIX_CEIL_INT32): New macros.
+
+2017-06-09  Werner Lemberg  <wl@gnu.org>
+
 	Remove unused macros.
 
 	* include/freetype/internal/ftcalc.h (ADD_INT, SUB_INT, MUL_INT,
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index 73961b9..4231be2 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -36,6 +36,7 @@
 #include FT_INTERNAL_AUTOHINT_H
 #include FT_INTERNAL_SERVICE_H
 #include FT_INTERNAL_PIC_H
+#include FT_INTERNAL_CALC_H
 
 #ifdef FT_CONFIG_OPTION_INCREMENTAL
 #include FT_INCREMENTAL_H
@@ -85,13 +86,29 @@ FT_BEGIN_HEADER
 
   /* we use FT_TYPEOF to suppress signedness compilation warnings */
 #define FT_PAD_FLOOR( x, n )  ( (x) & ~FT_TYPEOF( x )( (n)-1 ) )
-#define FT_PAD_ROUND( x, n )  FT_PAD_FLOOR( (x) + ((n)/2), n )
-#define FT_PAD_CEIL( x, n )   FT_PAD_FLOOR( (x) + ((n)-1), n )
+#define FT_PAD_ROUND( x, n )  FT_PAD_FLOOR( (x) + (n)/2, n )
+#define FT_PAD_CEIL( x, n )   FT_PAD_FLOOR( (x) + (n)-1, n )
 
 #define FT_PIX_FLOOR( x )     ( (x) & ~FT_TYPEOF( x )63 )
 #define FT_PIX_ROUND( x )     FT_PIX_FLOOR( (x) + 32 )
 #define FT_PIX_CEIL( x )      FT_PIX_FLOOR( (x) + 63 )
 
+  /* specialized versions (for signed values)                   */
+  /* that don't produce run-time errors due to integer overflow */
+#define FT_PAD_ROUND_LONG( x, n )  FT_PAD_FLOOR( ADD_LONG( (x), (n) / 2 ), \
+                                                 n )
+#define FT_PAD_CEIL_LONG( x, n )   FT_PAD_FLOOR( ADD_LONG( (x), (n) - 1 ), \
+                                                 n )
+#define FT_PIX_ROUND_LONG( x )     FT_PIX_FLOOR( ADD_LONG( (x), 32 ) )
+#define FT_PIX_CEIL_LONG( x )      FT_PIX_FLOOR( ADD_LONG( (x), 63 ) )
+
+#define FT_PAD_ROUND_INT32( x, n )  FT_PAD_FLOOR( ADD_INT32( (x), (n) / 2 ), \
+                                                  n )
+#define FT_PAD_CEIL_INT32( x, n )   FT_PAD_FLOOR( ADD_INT32( (x), (n) - 1 ), \
+                                                  n )
+#define FT_PIX_ROUND_INT32( x )     FT_PIX_FLOOR( ADD_INT32( (x), 32 ) )
+#define FT_PIX_CEIL_INT32( x )      FT_PIX_FLOOR( ADD_INT32( (x), 63 ) )
+
 
   /*
    *  character classification functions -- since these are used to parse