diff options
author | Benjamin Otte <otte@redhat.com> | 2010-08-23 18:20:09 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2010-08-24 12:17:50 +0200 |
commit | a8ea889e5e3029c2aad0e54e849783242daca274 (patch) | |
tree | 21db4a632d0ad1f2488aaa34f12be809773702c1 | |
parent | 4d8fb1bc01654ba0d331e6aea8127920e8cdf0b8 (diff) |
region: Fix pixman_region_translate() clipping bug
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.
-rw-r--r-- | pixman/pixman-region.c | 42 | ||||
-rw-r--r-- | pixman/pixman-region16.c | 4 | ||||
-rw-r--r-- | pixman/pixman-region32.c | 4 |
3 files changed, 29 insertions, 21 deletions
diff --git a/pixman/pixman-region.c b/pixman/pixman-region.c index 3ea88a00..4e7c8db7 100644 --- a/pixman/pixman-region.c +++ b/pixman/pixman-region.c @@ -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++; } diff --git a/pixman/pixman-region16.c b/pixman/pixman-region16.c index 46f5e26e..d88d3380 100644 --- a/pixman/pixman-region16.c +++ b/pixman/pixman-region16.c @@ -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 - diff --git a/pixman/pixman-region32.c b/pixman/pixman-region32.c index aeee86cf..abd6b1a9 100644 --- a/pixman/pixman-region32.c +++ b/pixman/pixman-region32.c @@ -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" |