pixman: Branch '0.18' - 2 commits
Benjamin Otte
company at kemper.freedesktop.org
Tue Aug 24 03:33:36 PDT 2010
.gitignore | 1 +
pixman/pixman-region.c | 42 +++++++++++++++++++++---------------------
pixman/pixman-region16.c | 4 ++++
pixman/pixman-region32.c | 4 ++++
test/Makefile.am | 2 ++
test/region-translate-test.c | 30 ++++++++++++++++++++++++++++++
6 files changed, 62 insertions(+), 21 deletions(-)
New commits:
commit 13951851cbbd81f9850d8ba132e155e3196ab522
Author: Benjamin Otte <otte at redhat.com>
Date: Mon Aug 23 18:20:09 2010 +0200
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.
diff --git a/pixman/pixman-region.c b/pixman/pixman-region.c
index a6a4005..d72773c 100644
--- a/pixman/pixman-region.c
+++ b/pixman/pixman-region.c
@@ -2194,7 +2194,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;
@@ -2204,7 +2204,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))
{
@@ -2219,7 +2219,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;
@@ -2228,15 +2228,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))
{
@@ -2249,22 +2249,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 46f5e26..d88d338 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 aeee86c..abd6b1a 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"
commit dd9243c1dd343a5867022a8290005a83bee4ce9e
Author: Benjamin Otte <otte at redhat.com>
Date: Tue Aug 24 12:28:25 2010 +0200
region: Add a new test region-translate
This test exercises a bug in pixman_region32_translate(). The function
clips the region to int16 coordinates SHRT_MIN/SHRT_MAX.
diff --git a/.gitignore b/.gitignore
index 96d222b..aaeb75f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ test/fetch-test
test/gradient-test
test/oob-test
test/region-test
+test/region-translate
test/scaling-test
test/screen-test
test/trap-crasher
diff --git a/test/Makefile.am b/test/Makefile.am
index 841ff8d..d6ff00f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,6 +4,7 @@ INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman
TESTPROGRAMS = \
a1-trap-test \
region-test \
+ region-translate-test \
fetch-test \
oob-test \
window-test \
@@ -19,6 +20,7 @@ composite_LDADD = $(TEST_LDADD)
trap_crasher_LDADD = $(TEST_LDADD)
oob_test_LDADD = $(TEST_LDADD)
window_test_LDADD = $(TEST_LDADD)
+region_translate_test_LDADD = $(TEST_LDADD)
region_test_LDADD = $(TEST_LDADD)
region_test_SOURCES = region-test.c utils.c utils.h
diff --git a/test/region-translate-test.c b/test/region-translate-test.c
new file mode 100644
index 0000000..0e96a5e
--- /dev/null
+++ b/test/region-translate-test.c
@@ -0,0 +1,30 @@
+#include <pixman.h>
+#include <assert.h>
+
+/* Pixman had a bug where 32bit regions where clipped to 16bit sizes when
+ * pixman_region32_translate() was called. This test exercises that bug.
+ */
+
+#define LARGE 32000
+
+int
+main (int argc, char **argv)
+{
+ pixman_box32_t rect = { -LARGE, -LARGE, LARGE, LARGE };
+ pixman_region32_t r1, r2;
+
+ pixman_region32_init_rects (&r1, &rect, 1);
+ pixman_region32_init_rect (&r2, rect.x1, rect.y1, rect.x2 - rect.x1, rect.y2 - rect.y1);
+
+ assert (pixman_region32_equal (&r1, &r2));
+
+ pixman_region32_translate (&r1, -LARGE, LARGE);
+ pixman_region32_translate (&r1, LARGE, -LARGE);
+
+ assert (pixman_region32_equal (&r1, &r2));
+
+ pixman_region32_fini (&r1);
+ pixman_region32_fini (&r2);
+
+ return 0;
+}
More information about the xorg-commit
mailing list