aboutsummaryrefslogtreecommitdiffhomepage
path: root/fuzz/FuzzCanvas.cpp
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-03-06 08:30:44 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-06 16:06:37 +0000
commitce540eae37a4e6aab8e888991e4d40c83a93f427 (patch)
tree5eaf5c553251f1ffcd5bdf4f8dc2008e96baba9a /fuzz/FuzzCanvas.cpp
parentfc026a63c32b37636d26baff73cc8d7a6d61ee7e (diff)
FuzzCanvas: fix BUG=skia:6321
Change-Id: I979b85cbe1eadca667d5d622bbbe24749da7b770 Reviewed-on: https://skia-review.googlesource.com/9289 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
Diffstat (limited to 'fuzz/FuzzCanvas.cpp')
-rw-r--r--fuzz/FuzzCanvas.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp
index 0dec81eb5e..31149753ef 100644
--- a/fuzz/FuzzCanvas.cpp
+++ b/fuzz/FuzzCanvas.cpp
@@ -64,41 +64,56 @@ static bool make_bool(Fuzz* fuzz) {
return b;
}
+// We don't always want to test NaNs.
+static void fuzz_nice_float(Fuzz* fuzz, float* f) {
+ fuzz->next(f);
+ if (*f != *f || ::fabs(*f) > 1.0e35f) {
+ *f = 0.0f;
+ }
+}
-template <int MAX_OPS>
-static void fuzz_path(Fuzz* fuzz, SkPath* path) {
+template <typename... Args>
+void fuzz_nice_float(Fuzz* fuzz, float* f, Args... rest) {
+ fuzz_nice_float(fuzz, f);
+ fuzz_nice_float(fuzz, rest...);
+}
+
+static void fuzz_path(Fuzz* fuzz, SkPath* path, int maxOps) {
+ if (maxOps < 2) {
+ maxOps = 2;
+ }
uint8_t fillType;
fuzz->nextRange(&fillType, 0, (uint8_t)SkPath::kInverseEvenOdd_FillType);
path->setFillType((SkPath::FillType)fillType);
uint8_t numOps;
- fuzz->nextRange(&numOps, 2, MAX_OPS);
+ fuzz->nextRange(&numOps, 2, maxOps);
for (uint8_t i = 0; i < numOps; ++i) {
uint8_t op;
fuzz->nextRange(&op, 0, 6);
SkScalar a, b, c, d, e, f;
switch (op) {
case 0:
- fuzz->next(&a, &b);
+ fuzz_nice_float(fuzz, &a, &b);
path->moveTo(a, b);
break;
case 1:
- fuzz->next(&a, &b);
+ fuzz_nice_float(fuzz, &a, &b);
path->lineTo(a, b);
break;
case 2:
- fuzz->next(&a, &b, &c, &d);
+ fuzz_nice_float(fuzz, &a, &b, &c, &d);
path->quadTo(a, b, c, d);
break;
case 3:
- fuzz->next(&a, &b, &c, &d, &e);
+ fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
path->conicTo(a, b, c, d, e);
break;
case 4:
- fuzz->next(&a, &b, &c, &d, &e, &f);
+ fuzz_nice_float(fuzz, &a, &b, &c, &d, &e, &f);
path->cubicTo(a, b, c, d, e, f);
break;
case 5:
- fuzz->next(&a, &b, &c, &d, &e);
+ fuzz_nice_float(fuzz, &a, &b, &c, &d, &e);
path->arcTo(a, b, c, d, e);
break;
case 6:
@@ -728,7 +743,7 @@ void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 4) {
}
case 21: {
SkPath path;
- fuzz_path<30>(fuzz, &path);
+ fuzz_path(fuzz, &path, 30);
int op;
bool doAntiAlias;
fuzz->next(&doAntiAlias);
@@ -807,7 +822,7 @@ void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 4) {
}
case 32: {
SkPath path;
- fuzz_path<60>(fuzz, &path);
+ fuzz_path(fuzz, &path, 60);
canvas->drawPath(path, paint);
break;
}
@@ -1039,7 +1054,7 @@ void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 4) {
FuzzPaintText(fuzz, &paint);
SkTDArray<uint8_t> text = fuzz_text(fuzz, paint);
SkPath path;
- fuzz_path<20>(fuzz, &path);
+ fuzz_path(fuzz, &path, 20);
SkScalar hOffset, vOffset;
fuzz->next(&hOffset, &vOffset);
canvas->drawTextOnPathHV(text.begin(), SkToSizeT(text.count()),
@@ -1056,7 +1071,7 @@ void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 4) {
FuzzPaintText(fuzz, &paint);
SkTDArray<uint8_t> text = fuzz_text(fuzz, paint);
SkPath path;
- fuzz_path<20>(fuzz, &path);
+ fuzz_path(fuzz, &path, 20);
canvas->drawTextOnPath(text.begin(), SkToSizeT(text.count()), path,
useMatrix ? &matrix : nullptr, paint);
break;