From 63f59ea89625bc2f445c5ab342c0f1c3971aabea Mon Sep 17 00:00:00 2001 From: Massimo Valentini Date: Tue, 23 Sep 2014 12:37:26 +0200 Subject: [PATCH] polygon-intersection: Try not to invoke undefined behaviour Optimizing compilers aggressively remove code that is executed only after an undefined behaviour occurred. Also, the difference of two (non char) pointers hides an integer division that, because the divisor is known at compile time, is transformed into a multiplication by a pseudo-reciprocal, and in this case the difference is not always a multiple of the divisor, resulting in an invalid comparison predicate. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=74779 Reviewed-by: Bryce Harrington --- src/cairo-polygon-intersect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cairo-polygon-intersect.c b/src/cairo-polygon-intersect.c index 02ef3b5e2..52e67752e 100644 --- a/src/cairo-polygon-intersect.c +++ b/src/cairo-polygon-intersect.c @@ -76,7 +76,7 @@ struct _cairo_bo_edge { #define PQ_LEFT_CHILD_INDEX(i) ((i) << 1) typedef enum { - CAIRO_BO_EVENT_TYPE_STOP, + CAIRO_BO_EVENT_TYPE_STOP = -1, CAIRO_BO_EVENT_TYPE_INTERSECTION, CAIRO_BO_EVENT_TYPE_START } cairo_bo_event_type_t; @@ -783,7 +783,7 @@ cairo_bo_event_compare (const cairo_bo_event_t *a, if (cmp) return cmp; - return a - b; + return a < b ? -1 : a == b ? 0 : 1; } static inline void