ccpr: Clamp the number of linear stroke segments

Clamps the number of linear segments before indexing into arrays with
it (oops). Also adds some minor fixups surrounding NaNs.

Bug: skia:8360
Change-Id: Id520ac49df2ebce71bda9fcaa0f164ddb6ddf2d2
Reviewed-on: https://skia-review.googlesource.com/154771
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ccpr/GrCCStrokeGeometry.cpp b/src/gpu/ccpr/GrCCStrokeGeometry.cpp
index 3fcafec..ec626b0 100644
--- a/src/gpu/ccpr/GrCCStrokeGeometry.cpp
+++ b/src/gpu/ccpr/GrCCStrokeGeometry.cpp
@@ -156,6 +156,7 @@
 
     // Decide how many flat line segments to chop the curve into.
     int numSegments = wangs_formula_quadratic(p0, p1, p2);
+    numSegments = SkTMin(numSegments, 1 << kMaxNumLinearSegmentsLog2);
     if (numSegments <= 1) {
         this->rotateTo(leftJoinVerb, normals[0]);
         this->lineTo(Verb::kInternalRoundJoin, P[2]);
@@ -283,6 +284,7 @@
 
     // Decide how many flat line segments to chop the curve into.
     int numSegments = wangs_formula_cubic(p0, p1, p2, p3);
+    numSegments = SkTMin(numSegments, 1 << kMaxNumLinearSegmentsLog2);
     if (numSegments <= 1) {
         this->rotateTo(leftJoinVerb, normals[0]);
         this->lineTo(leftJoinVerb, P[3]);