compute center slightly slower to avoid overflow

Bug: oss-fuzz:8509
Change-Id: I13b1a77e1549070827a7cc534b062ec85aad255e
Reviewed-on: https://skia-review.googlesource.com/129930
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/tests/RectTest.cpp b/tests/RectTest.cpp
index 7d2601a..2594c53 100644
--- a/tests/RectTest.cpp
+++ b/tests/RectTest.cpp
@@ -139,3 +139,24 @@
         }
     }
 }
+
+static float make_big_value(skiatest::Reporter* reporter) {
+    // need to make a big value, one that will cause rect.width() to overflow to inf.
+    // however, the windows compiler wants about this if it can see the big value inlined.
+    // hence, this stupid trick to try to fool their compiler.
+    SkASSERT(reporter);
+    return reporter ? SK_ScalarMax * 0.75f : 0;
+}
+
+DEF_TEST(Rect_center, reporter) {
+    // ensure we can compute center even when the width/height might overflow
+    const SkScalar big = make_big_value(reporter);
+    const SkRect r = { -big, -big, big, big };
+
+    REPORTER_ASSERT(reporter, r.isFinite());
+    REPORTER_ASSERT(reporter, SkScalarIsFinite(r.centerX()));
+    REPORTER_ASSERT(reporter, SkScalarIsFinite(r.centerY()));
+    REPORTER_ASSERT(reporter, !SkScalarIsFinite(r.width()));
+    REPORTER_ASSERT(reporter, !SkScalarIsFinite(r.height()));
+}
+