Use unsigned arithmetic for SkBitmapProcStateAutoMapper bias
authorFlorin Malita <fmalita@chromium.org>
Mon, 12 Dec 2016 20:43:51 +0000 (15:43 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 12 Dec 2016 21:25:37 +0000 (21:25 +0000)
To avoid undefined int underflow behavior.

BUG=skia:6017
R=mtklein@google.com,reed@google.com

Change-Id: Ib707ad5e1d87eda70525c56db14849c4164c5640
Reviewed-on: https://skia-review.googlesource.com/5861
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>

src/core/SkBitmapProcState.h

index cdf02ea9e00804f4487eaeb62808eeeb408c8e65..88e5193b2ae515cff1fff4616828379b84140886 100644 (file)
@@ -236,8 +236,11 @@ public:
             biasY = s.fFilterOneY >> 1;
         }
 
-        fX = SkScalarToFractionalInt(pt.x()) - SkFixedToFractionalInt(biasX);
-        fY = SkScalarToFractionalInt(pt.y()) - SkFixedToFractionalInt(biasY);
+        // punt to unsigned for defined underflow behavior
+        fX = (SkFractionalInt)((uint64_t)SkScalarToFractionalInt(pt.x()) -
+                               (uint64_t)SkFixedToFractionalInt(biasX));
+        fY = (SkFractionalInt)((uint64_t)SkScalarToFractionalInt(pt.y()) -
+                               (uint64_t)SkFixedToFractionalInt(biasY));
 
         if (scalarPoint) {
             scalarPoint->set(pt.x() - SkFixedToScalar(biasX),