region: Fix pixman_region_translate() clipping bug
authorBenjamin Otte <otte@redhat.com>
Mon, 23 Aug 2010 16:20:09 +0000 (18:20 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 24 Aug 2010 10:17:50 +0000 (12:17 +0200)
Fixes the region-translate test case by clipping region translations to
the newly defined PIXMAN_REGION_MIN/MAX and using the newly introduced
type overflow_int_t to check for the overflow.
Also uses INT16_MAX or INT32_MAX for these values instead of relying on
the size of short and int types.

pixman/pixman-region.c
pixman/pixman-region16.c
pixman/pixman-region32.c

index 3ea88a0..4e7c8db 100644 (file)
@@ -2212,7 +2212,7 @@ PIXMAN_EXPORT PREFIX (_contains_rectangle) (region_type_t *  region,
 PIXMAN_EXPORT void
 PREFIX (_translate) (region_type_t *region, int x, int y)
 {
-    int x1, x2, y1, y2;
+    overflow_int_t x1, x2, y1, y2;
     int nbox;
     box_type_t * pbox;
 
@@ -2222,7 +2222,7 @@ PREFIX (_translate) (region_type_t *region, int x, int y)
     region->extents.x2 = x2 = region->extents.x2 + x;
     region->extents.y2 = y2 = region->extents.y2 + y;
     
-    if (((x1 - SHRT_MIN) | (y1 - SHRT_MIN) | (SHRT_MAX - x2) | (SHRT_MAX - y2)) >= 0)
+    if (((x1 - PIXMAN_REGION_MIN) | (y1 - PIXMAN_REGION_MIN) | (PIXMAN_REGION_MAX - x2) | (PIXMAN_REGION_MAX - y2)) >= 0)
     {
         if (region->data && (nbox = region->data->numRects))
         {
@@ -2237,7 +2237,7 @@ PREFIX (_translate) (region_type_t *region, int x, int y)
         return;
     }
 
-    if (((x2 - SHRT_MIN) | (y2 - SHRT_MIN) | (SHRT_MAX - x1) | (SHRT_MAX - y1)) <= 0)
+    if (((x2 - PIXMAN_REGION_MIN) | (y2 - PIXMAN_REGION_MIN) | (PIXMAN_REGION_MAX - x1) | (PIXMAN_REGION_MAX - y1)) <= 0)
     {
         region->extents.x2 = region->extents.x1;
         region->extents.y2 = region->extents.y1;
@@ -2246,15 +2246,15 @@ PREFIX (_translate) (region_type_t *region, int x, int y)
         return;
     }
 
-    if (x1 < SHRT_MIN)
-       region->extents.x1 = SHRT_MIN;
-    else if (x2 > SHRT_MAX)
-       region->extents.x2 = SHRT_MAX;
+    if (x1 < PIXMAN_REGION_MIN)
+       region->extents.x1 = PIXMAN_REGION_MIN;
+    else if (x2 > PIXMAN_REGION_MAX)
+       region->extents.x2 = PIXMAN_REGION_MAX;
 
-    if (y1 < SHRT_MIN)
-       region->extents.y1 = SHRT_MIN;
-    else if (y2 > SHRT_MAX)
-       region->extents.y2 = SHRT_MAX;
+    if (y1 < PIXMAN_REGION_MIN)
+       region->extents.y1 = PIXMAN_REGION_MIN;
+    else if (y2 > PIXMAN_REGION_MAX)
+       region->extents.y2 = PIXMAN_REGION_MAX;
 
     if (region->data && (nbox = region->data->numRects))
     {
@@ -2267,22 +2267,22 @@ PREFIX (_translate) (region_type_t *region, int x, int y)
             pbox_out->x2 = x2 = pbox->x2 + x;
             pbox_out->y2 = y2 = pbox->y2 + y;
 
-            if (((x2 - SHRT_MIN) | (y2 - SHRT_MIN) |
-                 (SHRT_MAX - x1) | (SHRT_MAX - y1)) <= 0)
+            if (((x2 - PIXMAN_REGION_MIN) | (y2 - PIXMAN_REGION_MIN) |
+                 (PIXMAN_REGION_MAX - x1) | (PIXMAN_REGION_MAX - y1)) <= 0)
             {
                 region->data->numRects--;
                 continue;
            }
 
-            if (x1 < SHRT_MIN)
-               pbox_out->x1 = SHRT_MIN;
-            else if (x2 > SHRT_MAX)
-               pbox_out->x2 = SHRT_MAX;
+            if (x1 < PIXMAN_REGION_MIN)
+               pbox_out->x1 = PIXMAN_REGION_MIN;
+            else if (x2 > PIXMAN_REGION_MAX)
+               pbox_out->x2 = PIXMAN_REGION_MAX;
 
-            if (y1 < SHRT_MIN)
-               pbox_out->y1 = SHRT_MIN;
-            else if (y2 > SHRT_MAX)
-               pbox_out->y2 = SHRT_MAX;
+            if (y1 < PIXMAN_REGION_MIN)
+               pbox_out->y1 = PIXMAN_REGION_MIN;
+            else if (y2 > PIXMAN_REGION_MAX)
+               pbox_out->y2 = PIXMAN_REGION_MAX;
 
             pbox_out++;
        }
index 46f5e26..d88d338 100644 (file)
@@ -35,6 +35,7 @@
 typedef pixman_box16_t         box_type_t;
 typedef pixman_region16_data_t region_data_type_t;
 typedef pixman_region16_t      region_type_t;
+typedef int32_t                 overflow_int_t;
 
 typedef struct {
     int x, y;
@@ -42,6 +43,9 @@ typedef struct {
 
 #define PREFIX(x) pixman_region##x
 
+#define PIXMAN_REGION_MAX INT16_MAX
+#define PIXMAN_REGION_MIN INT16_MIN
+
 #include "pixman-region.c"
 
 /* This function exists only to make it possible to preserve the X ABI -
index aeee86c..abd6b1a 100644 (file)
@@ -33,6 +33,7 @@
 typedef pixman_box32_t         box_type_t;
 typedef pixman_region32_data_t region_data_type_t;
 typedef pixman_region32_t      region_type_t;
+typedef int64_t                 overflow_int_t;
 
 typedef struct {
     int x, y;
@@ -40,4 +41,7 @@ typedef struct {
 
 #define PREFIX(x) pixman_region32##x
 
+#define PIXMAN_REGION_MAX INT32_MAX
+#define PIXMAN_REGION_MIN INT32_MIN
+
 #include "pixman-region.c"