Bug 1292443 - Use unsigned integer arithmetic to avoid UB. r=dholbert
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Thu, 20 Oct 2016 21:15:27 +0200
changeset 427716 fbd443ce8fb5b8a1897baac3bfe62f8c5c5b054f
parent 427715 3201c03e0c16fcba25c23af79cec8b08ea174ab7
child 427717 c1559b3712f202267981d82a70fb25299e776e84
push id33099
push userdholbert@mozilla.com
push dateThu, 20 Oct 2016 20:25:54 +0000
reviewersdholbert
bugs1292443
milestone52.0a1
Bug 1292443 - Use unsigned integer arithmetic to avoid UB. r=dholbert
gfx/cairo/libpixman/src/pixman-edge-imp.h
--- a/gfx/cairo/libpixman/src/pixman-edge-imp.h
+++ b/gfx/cairo/libpixman/src/pixman-edge-imp.h
@@ -50,18 +50,19 @@ RASTERIZE_EDGES (pixman_image_t  *image,
 #if N_BITS == 1
 	/* For the non-antialiased case, round the coordinates up, in effect
 	 * sampling just slightly to the left of the pixel. This is so that
 	 * when the sample point lies exactly on the line, we round towards
 	 * north-west.
 	 *
 	 * (The AA case does a similar  adjustment in RENDER_SAMPLES_X)
 	 */
-	lx += X_FRAC_FIRST(1) - pixman_fixed_e;
-	rx += X_FRAC_FIRST(1) - pixman_fixed_e;
+        /* we cast to unsigned to get defined behaviour for overflow */
+	lx = (unsigned)lx + X_FRAC_FIRST(1) - pixman_fixed_e;
+	rx = (unsigned)rx + X_FRAC_FIRST(1) - pixman_fixed_e;
 #endif
 	/* clip X */
 	if (lx < 0)
 	    lx = 0;
 	if (pixman_fixed_to_int (rx) >= width)
 #if N_BITS == 1
 	    rx = pixman_int_to_fixed (width);
 #else