summaryrefslogtreecommitdiff
path: root/src/cairo-rectangle.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-10-23 13:37:41 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-10-30 16:19:26 +0000
commit0e4156121f05b14f800289ea34c5382de1f20869 (patch)
tree908ddb852608ff68033ca8b370c25f162f89dc7d /src/cairo-rectangle.c
parent2464b8a0a9f7db7421c257eb4e3ac0d98af34761 (diff)
downloadcairo-0e4156121f05b14f800289ea34c5382de1f20869.tar.gz
[rectangle] Fix unsigned promotion whilst computing intersect.
_cairo_rectangle_intersect() incorrectly allows unsigned promotion during its arithmetic.
Diffstat (limited to 'src/cairo-rectangle.c')
-rw-r--r--src/cairo-rectangle.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/cairo-rectangle.c b/src/cairo-rectangle.c
index 3618ba0b2..ec08db42e 100644
--- a/src/cairo-rectangle.c
+++ b/src/cairo-rectangle.c
@@ -96,29 +96,32 @@ _cairo_box_round_to_rectangle (const cairo_box_t *box,
}
void
-_cairo_rectangle_intersect (cairo_rectangle_int_t *dest, cairo_rectangle_int_t *src)
+_cairo_rectangle_intersect (cairo_rectangle_int_t *dst,
+ const cairo_rectangle_int_t *src)
{
int x1, y1, x2, y2;
- x1 = MAX (dest->x, src->x);
- y1 = MAX (dest->y, src->y);
- x2 = MIN (dest->x + dest->width, src->x + src->width);
- y2 = MIN (dest->y + dest->height, src->y + src->height);
+ x1 = MAX (dst->x, src->x);
+ y1 = MAX (dst->y, src->y);
+ /* Beware the unsigned promotion, fortunately we have bits to spare
+ * as (CAIRO_RECT_INT_MAX - CAIRO_RECT_INT_MIN) < UINT_MAX
+ */
+ x2 = MIN (dst->x + (int) dst->width, src->x + (int) src->width);
+ y2 = MIN (dst->y + (int) dst->height, src->y + (int) src->height);
if (x1 >= x2 || y1 >= y2) {
- dest->x = 0;
- dest->y = 0;
- dest->width = 0;
- dest->height = 0;
+ dst->x = 0;
+ dst->y = 0;
+ dst->width = 0;
+ dst->height = 0;
} else {
- dest->x = x1;
- dest->y = y1;
- dest->width = x2 - x1;
- dest->height = y2 - y1;
+ dst->x = x1;
+ dst->y = y1;
+ dst->width = x2 - x1;
+ dst->height = y2 - y1;
}
}
-
#define P1x (line->p1.x)
#define P1y (line->p1.y)
#define P2x (line->p2.x)