aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-05-01 09:13:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-01 19:58:45 +0000
commit3fc6a185ca5de3fc25ec50726944afc525856863 (patch)
tree0f83ad41f0841a1e62b295470d864885628dbf47
parent91368c9b9b0c3071babb3352646f9795e0b828fd (diff)
Fix index overflow check for rewriting fans as triangles.
Not only could the old test cause int overflow, it was just wrong. Bug: skia:8085 Change-Id: Id6b81f4aa1b115f0dbfd2266aee8fab5d5d30aee Reviewed-on: https://skia-review.googlesource.com/124779 Reviewed-by: Chris Dalton <csmartdalton@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
-rw-r--r--src/core/SkVertices.cpp2
-rw-r--r--tests/VerticesTest.cpp4
2 files changed, 3 insertions, 3 deletions
diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp
index c945fc00e9..abe2b4ce67 100644
--- a/src/core/SkVertices.cpp
+++ b/src/core/SkVertices.cpp
@@ -42,7 +42,7 @@ struct SkVertices::Sizes {
numFanTris = vertexCount - 2;
// By forcing this to become indexed we are adding a constraint to the maximum
// number of vertices.
- if (3 * numFanTris > (SK_MaxU16 + 1)) {
+ if (vertexCount > (SK_MaxU16 + 1)) {
sk_bzero(this, sizeof(*this));
return;
}
diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp
index 5bcb11f1d3..59d06472ac 100644
--- a/tests/VerticesTest.cpp
+++ b/tests/VerticesTest.cpp
@@ -91,13 +91,13 @@ DEF_TEST(Vertices, reporter) {
{
// This has the maximum number of vertices to be rewritten as indexed triangles without
// overflowing a 16bit index.
- SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 21847, 0,
+ SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, SK_MaxU16 + 1, 0,
SkVertices::kHasColors_BuilderFlag);
REPORTER_ASSERT(reporter, builder.isValid());
}
{
// This has too many to be rewritten.
- SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, 21848, 0,
+ SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, SK_MaxU16 + 2, 0,
SkVertices::kHasColors_BuilderFlag);
REPORTER_ASSERT(reporter, !builder.isValid());
}