mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 15:48:00 +02:00
[rectangle] Fix unsigned promotion whilst computing intersect.
_cairo_rectangle_intersect() incorrectly allows unsigned promotion during its arithmetic.
This commit is contained in:
parent
2464b8a0a9
commit
0e4156121f
2 changed files with 19 additions and 15 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -254,7 +254,8 @@ _cairo_box_round_to_rectangle (const cairo_box_t *box,
|
|||
cairo_rectangle_int_t *rectangle);
|
||||
|
||||
cairo_private 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);
|
||||
|
||||
cairo_private cairo_bool_t
|
||||
_cairo_box_intersects_line_segment (cairo_box_t *box, cairo_line_t *line);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue