[M52] add fail condition to addexpanded

(cherry-pick of 013e0e6d482f61181b829bf5ebfcad912c0061b1)

If coincident pairs don't match,
give up rather than deref null.

TBR=fmalita@chromium.org,caryclark@google.com
BUG=618991
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2058773002

Review-Url: https://codereview.chromium.org/2058773002
NOTREECHECKS=true
NOTRY=true
NOPRESUBMIT=true

Review-Url: https://codereview.chromium.org/2078183002
diff --git a/src/pathops/SkOpCoincidence.cpp b/src/pathops/SkOpCoincidence.cpp
index 130d1da..9ef4e0a 100755
--- a/src/pathops/SkOpCoincidence.cpp
+++ b/src/pathops/SkOpCoincidence.cpp
@@ -133,6 +133,9 @@
             }
             if (oTest != oEnd) {
                 oTest = coin->fFlipped ? oTest->prev() : oTest->upCast()->next();
+                if (!oTest) {
+                    return false;
+                }
             }
         }
     } while ((coin = coin->fNext));
diff --git a/tests/PathOpsBuilderTest.cpp b/tests/PathOpsBuilderTest.cpp
index e191ece..1bf34e0 100644
--- a/tests/PathOpsBuilderTest.cpp
+++ b/tests/PathOpsBuilderTest.cpp
@@ -301,3 +301,24 @@
     SkPath result;
     builder.resolve(&result);
 }
+
+DEF_TEST(SkOpBuilder618991, reporter) {
+    SkPath path0;
+    path0.moveTo(140, 40);
+    path0.lineTo(200, 210);
+    path0.lineTo(40, 100);
+    path0.lineTo(2.22223e+07f, 2.22222e+14f);
+    path0.lineTo(2.22223e+07f, 2.22222e+14f);
+
+    SkPath path1;
+    path1.moveTo(160, 60);
+    path1.lineTo(220, 230);
+    path1.lineTo(60, 120);
+    path1.lineTo(2.22223e+07f, 2.22222e+14f);
+    path1.lineTo(2.22223e+07f, 2.22222e+14f);
+
+    SkOpBuilder builder;
+    builder.add(path0, SkPathOp::kUnion_SkPathOp);
+    builder.add(path1, SkPathOp::kUnion_SkPathOp);
+    builder.resolve(&path0);
+}