Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: src/core/SkMatrix.cpp

Issue 2143133005: Guard SkMatrix::get*Scale[s]() against negative nearly-zero values. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: guard against inf too, update the condition to better suit negative nearly-zeros and added unit tes… Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/MatrixTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMatrix.cpp
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 492f3f6ac447fd3575dbcb775b6a7abf4531644b..fc698530ec9d2b01a31778d70a5198b5ea61e993 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1568,15 +1568,21 @@ template <MinMaxOrBoth MIN_MAX_OR_BOTH> bool get_scale_factor(SkMatrix::TypeMask
results[1] = apluscdiv2 + x;
}
}
- if (SkScalarIsNaN(results[0])) {
+ if (!SkScalarIsFinite(results[0])) {
return false;
}
+ if (results[0] < 0 && results[0] > -SK_ScalarNearlyZero) {
jvanverth1 2016/07/15 13:49:05 I missed something here -- why was this changed to
reed1 2016/07/17 00:15:17 Agreed. This reads oddly -- we clamp nearly-zero-n
+ results[0] = 0;
+ }
SkASSERT(results[0] >= 0);
results[0] = SkScalarSqrt(results[0]);
if (kBoth_MinMaxOrBoth == MIN_MAX_OR_BOTH) {
- if (SkScalarIsNaN(results[1])) {
+ if (!SkScalarIsFinite(results[1])) {
return false;
}
+ if (results[1] < 0 && results[1] > -SK_ScalarNearlyZero) {
+ results[1] = 0;
+ }
SkASSERT(results[1] >= 0);
results[1] = SkScalarSqrt(results[1]);
}
« no previous file with comments | « no previous file | tests/MatrixTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698