From f611f9580469661e585f419a7dd033ddffd7e20d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 24 Oct 2014 09:41:47 +0100 Subject: [PATCH] sna/trapezoids: Difference between two 32-bit quantities is 33-bits in size When computing the edge distance, we subtract on 32-bit quantity from another. This requires 33-bits to store the full result so promote the subtraction to 64-bits (rather than the result of that subtraction as done currently). Reported-by: Jiri Slaby Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=70461#c76 Signed-off-by: Chris Wilson --- src/sna/sna_trapezoids_imprecise.c | 8 ++++---- src/sna/sna_trapezoids_precise.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sna/sna_trapezoids_imprecise.c b/src/sna/sna_trapezoids_imprecise.c index f88a8ae5..37def2f9 100644 --- a/src/sna/sna_trapezoids_imprecise.c +++ b/src/sna/sna_trapezoids_imprecise.c @@ -500,8 +500,8 @@ polygon_add_edge(struct polygon *polygon, } else { int64_t Ex, Ey, tmp; - Ex = (int64_t)(edge->p2.x - edge->p1.x) * FAST_SAMPLES_X; - Ey = (int64_t)(edge->p2.y - edge->p1.y) * FAST_SAMPLES_Y * (2 << 16); + Ex = ((int64_t)edge->p2.x - edge->p1.x) * FAST_SAMPLES_X; + Ey = ((int64_t)edge->p2.y - edge->p1.y) * FAST_SAMPLES_Y * (2 << 16); assert(Ey > 0); e->dxdy.quo = Ex * (2 << 16) / Ey; @@ -594,8 +594,8 @@ polygon_add_line(struct polygon *polygon, } else { int64_t Ex, Ey, tmp; - Ex = (int64_t)(p2->x - p1->x) * FAST_SAMPLES_X; - Ey = (int64_t)(p2->y - p1->y) * FAST_SAMPLES_Y * (2 << 16); + Ex = ((int64_t)p2->x - p1->x) * FAST_SAMPLES_X; + Ey = ((int64_t)p2->y - p1->y) * FAST_SAMPLES_Y * (2 << 16); e->dxdy.quo = Ex * (2 << 16) / Ey; e->dxdy.rem = Ex * (2 << 16) % Ey; diff --git a/src/sna/sna_trapezoids_precise.c b/src/sna/sna_trapezoids_precise.c index 9925654d..9187ab48 100644 --- a/src/sna/sna_trapezoids_precise.c +++ b/src/sna/sna_trapezoids_precise.c @@ -553,8 +553,8 @@ polygon_add_edge(struct polygon *polygon, edge->p2.x - edge->p1.x, edge->p2.y - edge->p1.y)); - Ex = (int64_t)(edge->p2.x - edge->p1.x) * SAMPLES_X; - Ey = (int64_t)(edge->p2.y - edge->p1.y) * SAMPLES_Y * (2 << 16); + Ex = ((int64_t)edge->p2.x - edge->p1.x) * SAMPLES_X; + Ey = ((int64_t)edge->p2.y - edge->p1.y) * SAMPLES_Y * (2 << 16); assert(Ey > 0); e->dxdy.quo = Ex * (2 << 16) / Ey; e->dxdy.rem = Ex * (2 << 16) % Ey; @@ -663,8 +663,8 @@ polygon_add_line(struct polygon *polygon, p2->x - p1->x, p2->y - p1->y)); - Ex = (int64_t)(p2->x - p1->x) * SAMPLES_X; - Ey = (int64_t)(p2->y - p1->y) * SAMPLES_Y * (2 << 16); + Ex = ((int64_t)p2->x - p1->x) * SAMPLES_X; + Ey = ((int64_t)p2->y - p1->y) * SAMPLES_Y * (2 << 16); e->dxdy.quo = Ex * (2 << 16) / Ey; e->dxdy.rem = Ex * (2 << 16) % Ey;