be consistent about int for incReserve
Bug: 883666
Change-Id: I4070c958ef9ac5891ea75a8ef349e3d362c97f54
Reviewed-on: https://skia-review.googlesource.com/c/162620
Auto-Submit: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
(cherry picked from commit 6a388006f5e3b270d206fb4c7e24accadb1c790f)
Reviewed-on: https://skia-review.googlesource.com/c/170347
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Heather Miller <hcm@google.com>
diff --git a/docs/SkPath_Reference.bmh b/docs/SkPath_Reference.bmh
index 1ed7b46..a23c880 100644
--- a/docs/SkPath_Reference.bmh
+++ b/docs/SkPath_Reference.bmh
@@ -1884,7 +1884,7 @@
# ------------------------------------------------------------------------------
-#Method void incReserve(unsigned extraPtCount)
+#Method void incReserve(int extraPtCount)
#In Utility
#Line # reserves space for additional data ##
Grows Path Verb_Array and Point_Array to contain extraPtCount additional Points.
@@ -4222,26 +4222,26 @@
#Example
void draw(SkCanvas* canvas) {
- SkPaint paint;
- paint.setAntiAlias(true);
- SkRRect rrect;
- rrect.setRectXY({40, 40, 215, 215}, 50, 50);
- SkPath path;
- path.addRRect(rrect);
- canvas->drawPath(path, paint);
- for (int start = 0; start < 8; ++start) {
- SkPath textPath;
- textPath.addRRect(rrect, SkPath::kCW_Direction, start);
- SkPathMeasure pathMeasure(textPath, false);
- SkPoint position;
- SkVector tangent;
- if (!pathMeasure.getPosTan(0, &position, &tangent)) {
- continue;
- }
- SkRSXform rsxForm = SkRSXform::Make(tangent.fX, tangent.fY,
- position.fX + tangent.fY * 5, position.fY - tangent.fX * 5);
- canvas->drawTextRSXform(&"01234567"[start], 1, &rsxForm, nullptr, paint);
- }
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ SkRRect rrect;
+ rrect.setRectXY({40, 40, 215, 215}, 50, 50);
+ SkPath path;
+ path.addRRect(rrect);
+ canvas->drawPath(path, paint);
+ for (int start = 0; start < 8; ++start) {
+ SkPath textPath;
+ textPath.addRRect(rrect, SkPath::kCW_Direction, start);
+ SkPathMeasure pathMeasure(textPath, false);
+ SkPoint position;
+ SkVector tangent;
+ if (!pathMeasure.getPosTan(0, &position, &tangent)) {
+ continue;
+ }
+ SkRSXform rsxForm = SkRSXform::Make(tangent.fX, tangent.fY,
+ position.fX + tangent.fY * 5, position.fY - tangent.fX * 5);
+ canvas->drawTextRSXform(&"01234567"[start], 1, &rsxForm, nullptr, paint);
+ }
}
##
diff --git a/include/core/SkPath.h b/include/core/SkPath.h
index fd044a6..0f837f5 100644
--- a/include/core/SkPath.h
+++ b/include/core/SkPath.h
@@ -549,7 +549,7 @@
@param extraPtCount number of additional SkPoint to allocate
*/
- void incReserve(unsigned extraPtCount);
+ void incReserve(int extraPtCount);
/** Shrinks SkPath verb array and SkPoint array storage to discard unused capacity.
May reduce the heap overhead for SkPath known to be fully constructed.
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 94ed8cc..af8cf9e 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -757,9 +757,11 @@
fFirstDirection = SkPathPriv::kUnknown_FirstDirection; \
} while (0)
-void SkPath::incReserve(U16CPU inc) {
+void SkPath::incReserve(int inc) {
SkDEBUGCODE(this->validate();)
- SkPathRef::Editor(&fPathRef, inc, inc);
+ if (inc > 0) {
+ SkPathRef::Editor(&fPathRef, inc, inc);
+ }
SkDEBUGCODE(this->validate();)
}
diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp
index 8c8e7fb..f767323 100644
--- a/src/core/SkPathRef.cpp
+++ b/src/core/SkPathRef.cpp
@@ -30,6 +30,9 @@
int incReserveVerbs,
int incReservePoints)
{
+ SkASSERT(incReserveVerbs >= 0);
+ SkASSERT(incReservePoints >= 0);
+
if ((*pathRef)->unique()) {
(*pathRef)->incReserve(incReserveVerbs, incReservePoints);
} else {
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 16d094c..febfd4f 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -5191,3 +5191,16 @@
REPORTER_ASSERT(r, p.isValid());
REPORTER_ASSERT(r, p.pathRefIsValid());
}
+
+DEF_TEST(Path_increserve_handle_neg_crbug_883666, r) {
+ SkPath path;
+
+ path.conicTo({0, 0}, {1, 1}, SK_FloatNegativeInfinity);
+
+ // <== use a copy path object to force SkPathRef::copy() and SkPathRef::resetToSize()
+ SkPath shallowPath = path;
+
+ // make sure we don't assert/crash on this.
+ shallowPath.incReserve(0xffffffff);
+}
+