diff options
author | herb <herb@google.com> | 2016-01-22 08:34:35 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-22 08:34:35 -0800 |
commit | 5e0883cf57176134155fb70c9bc51dbb0f0c67fb (patch) | |
tree | 4348dd9a8a5d9e56b0b6ed848f3d86eae85c4a4e /src/core/SkScaleToSides.h | |
parent | 5286f0222ccb65ce1dbe235adc225b79057dd0ae (diff) |
Fix bounds of checking if a radii are too long for a side.
BUG=skia:4692,skia:4413
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1617763003
Review URL: https://codereview.chromium.org/1617763003
Diffstat (limited to 'src/core/SkScaleToSides.h')
-rw-r--r-- | src/core/SkScaleToSides.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/core/SkScaleToSides.h b/src/core/SkScaleToSides.h index 77637a3ac2..c3fa172f67 100644 --- a/src/core/SkScaleToSides.h +++ b/src/core/SkScaleToSides.h @@ -14,7 +14,7 @@ class ScaleToSides { public: - // This code assumes that a and b fit in in a float, and therefore the resulting smaller value + // This code assumes that a and b fit in a float, and therefore the resulting smaller value // of a and b will fit in a float. The side of the rectangle may be larger than a float. // Scale must be less than or equal to the ratio limit / (*a + *b). // This code assumes that NaN and Inf are never passed in. @@ -24,8 +24,7 @@ public: *a = (float)((double)*a * scale); *b = (float)((double)*b * scale); - // This check is conservative. (double)*a + (double)*b >= (double)(*a + *b) - if ((double)*a + (double)*b > limit) { + if (*a + *b > limit) { float* minRadius = a; float* maxRadius = b; @@ -48,14 +47,16 @@ public: // reduced by one ULP to be less than limit - newMinRadius. // Note: nexttowardf is a c99 call and should be std::nexttoward, but this is not // implemented in the ARM compiler. - if ((double)newMaxRadius + (double)newMinRadius > limit) { + if (newMaxRadius + newMinRadius > limit) { newMaxRadius = nexttowardf(newMaxRadius, 0.0); } *maxRadius = newMaxRadius; } - SkASSERTF(*a >= 0.0f && *b >= 0.0f, "a: %g, b: %g", *a, *b); - SkASSERTF((*a + *b) <= limit, "limit: %g, a: %g, b: %g", limit, *a, *b); + SkASSERTF(*a >= 0.0f && *b >= 0.0f, "a: %g, b: %g, limit: %g, scale: %g", *a, *b, limit, + scale); + SkASSERTF(*a + *b <= limit, "\nlimit: %.10f, a: %.10f, b: %.10f, scale: %.20f", + limit, *a, *b, scale); } }; #endif // ScaleToSides_DEFINED |