Bug 1531025 part 2: Skip an unnecessary border-radius calculation if the radii are 0 (to avoid division by 0). r=boris
☠☠ backed out by 1003ed8243c5 ☠ ☠
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 28 Feb 2019 23:52:51 +0000
changeset 519719 fd71937c6f25db7365001a491e32f283a41397e7
parent 519718 e4028e1ca6c7f6b62ba06ab10abfcb2301a4257d
child 519720 a1c9f35a9652aa11b47b65bd18313100c5cb5b63
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersboris
bugs1531025
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1531025 part 2: Skip an unnecessary border-radius calculation if the radii are 0 (to avoid division by 0). r=boris This patch avoids a potential division by 0 (one that's unlikely to be triggered by real content), for correctness and robustness. This patch isn't really changing the logic, because the newly-guarded code is already guarded by a "length < sum" check, and "length" is expected to be nonnegative [1], which means "sum" would already have been nonzero in cases where the existing strict less-than comparison returned true. [1] except for integer overflow or other bizarreness. Depends on D21578 Differential Revision: https://phabricator.services.mozilla.com/D21579
layout/generic/nsFrame.cpp
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -1690,21 +1690,20 @@ bool nsIFrame::ComputeBorderRadii(const 
   NS_FOR_CSS_SIDES(side) {
     uint32_t hc1 = SideToHalfCorner(side, false, true);
     uint32_t hc2 = SideToHalfCorner(side, true, true);
     nscoord length =
         SideIsVertical(side) ? aBorderArea.height : aBorderArea.width;
     nscoord sum = aRadii[hc1] + aRadii[hc2];
     if (sum) {
       haveRadius = true;
-    }
-
-    // avoid floating point division in the normal case
-    if (length < sum) {
-      ratio = std::min(ratio, double(length) / sum);
+      // avoid floating point division in the normal case
+      if (length < sum) {
+        ratio = std::min(ratio, double(length) / sum);
+      }
     }
   }
   if (ratio < 1.0) {
     NS_FOR_CSS_HALF_CORNERS(corner) { aRadii[corner] *= ratio; }
   }
 
   return haveRadius;
 }