Bug 791428 - Limit pixel sizes so that they can't exceed app unit limits. r=roc
☠☠ backed out by 1494dd3c2315 ☠ ☠
authorAnthony Jones <ajones@mozilla.com>
Mon, 22 Oct 2012 22:22:27 -0400
changeset 111240 d587ce3af2f357775ac939e346fc1de374a264a3
parent 111239 9ae8f8f7028fbd5793247806c7ffcaaf3ed79a67
child 111241 9e1b8da160a290d32432560eb7c551aaf5c5ec5a
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersroc
bugs791428
milestone19.0a1
Bug 791428 - Limit pixel sizes so that they can't exceed app unit limits. r=roc
gfx/src/nsCoord.h
--- a/gfx/src/nsCoord.h
+++ b/gfx/src/nsCoord.h
@@ -439,16 +439,32 @@ inline nscoord NSFloatPixelsToAppUnits(f
 {
   return NSToCoordRoundWithClamp(aPixels * aAppUnitsPerPixel);
 }
 
 inline nscoord NSIntPixelsToAppUnits(int32_t aPixels, int32_t aAppUnitsPerPixel)
 {
   // The cast to nscoord makes sure we don't overflow if we ever change
   // nscoord to float
+#ifndef NS_COORD_IS_FLOAT
+  const int pixels_MAX = nscoord_MAX / aAppUnitsPerPixel;
+  // Bounds-check before converting out of float, to avoid overflow
+  NS_WARN_IF_FALSE(aPixels <= pixels_MAX,
+                   "Overflowed nscoord_MAX in conversion to nscoord");
+  if (aPixels >= pixels_MAX) {
+    aPixels = pixels_MAX;
+  } else {
+    const int pixels_MIN = nscoord_MIN / aAppUnitsPerPixel;
+    NS_WARN_IF_FALSE(aPixels >= pixels_MIN,
+                     "Overflowed nscoord_MIN in conversion to nscoord");
+    if (aPixels <= pixels_MIN) {
+      aPixels = pixels_MIN;
+    }
+  }
+#endif
   nscoord r = aPixels * (nscoord)aAppUnitsPerPixel;
   VERIFY_COORD(r);
   return r;
 }
 
 inline float NSAppUnitsToFloatPixels(nscoord aAppUnits, float aAppUnitsPerPixel)
 {
   return (float(aAppUnits) / aAppUnitsPerPixel);