diff options
author | Kevin Lubick <kjlubick@google.com> | 2016-11-01 15:01:12 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-01 19:23:16 +0000 |
commit | 2f535cecd0e5a19a3dfb76649b1d90c7e158e24c (patch) | |
tree | 685d9bb66afe495239373aeb8a3a86fd1843e6c3 /fuzz/FuzzPathop.cpp | |
parent | 1f49f26353997195030aeab41c8665e1860d2958 (diff) |
Make fuzzers use cleaner interface
signalBoring() no longer exists. When the fuzzer runs out of randomness,
it just returns 0. Fuzzers should not go into infinite loops if this
happens. do while loops are particularly error-prone.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3963
Change-Id: Iebcfc14cc6b0a19c5dd015cd39875c81fa44003e
Reviewed-on: https://skia-review.googlesource.com/3963
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'fuzz/FuzzPathop.cpp')
-rw-r--r-- | fuzz/FuzzPathop.cpp | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/fuzz/FuzzPathop.cpp b/fuzz/FuzzPathop.cpp index fecf3ca914..a555cd6344 100644 --- a/fuzz/FuzzPathop.cpp +++ b/fuzz/FuzzPathop.cpp @@ -14,51 +14,33 @@ const int kLastOp = SkPathOp::kReverseDifference_SkPathOp; void BuildPath(Fuzz* fuzz, SkPath* path, int last_verb) { - uint8_t operation; - SkScalar a, b, c, d, e, f; - while (fuzz->next<uint8_t>(&operation)) { + while (!fuzz->exhausted()) { + uint8_t operation = fuzz->next<uint8_t>(); switch (operation % (last_verb + 1)) { case SkPath::Verb::kMove_Verb: - if (!fuzz->next<SkScalar>(&a) || !fuzz->next<SkScalar>(&b)) - return; - path->moveTo(a, b); + path->moveTo(fuzz->next<SkScalar>(), fuzz->next<SkScalar>()); break; case SkPath::Verb::kLine_Verb: - if (!fuzz->next<SkScalar>(&a) || !fuzz->next<SkScalar>(&b)) - return; - path->lineTo(a, b); + path->lineTo(fuzz->next<SkScalar>(), fuzz->next<SkScalar>()); break; case SkPath::Verb::kQuad_Verb: - if (!fuzz->next<SkScalar>(&a) || - !fuzz->next<SkScalar>(&b) || - !fuzz->next<SkScalar>(&c) || - !fuzz->next<SkScalar>(&d)) - return; - path->quadTo(a, b, c, d); + path->quadTo(fuzz->next<SkScalar>(), fuzz->next<SkScalar>(), + fuzz->next<SkScalar>(), fuzz->next<SkScalar>()); break; case SkPath::Verb::kConic_Verb: - if (!fuzz->next<SkScalar>(&a) || - !fuzz->next<SkScalar>(&b) || - !fuzz->next<SkScalar>(&c) || - !fuzz->next<SkScalar>(&d) || - !fuzz->next<SkScalar>(&e)) - return; - path->conicTo(a, b, c, d, e); + path->conicTo(fuzz->next<SkScalar>(), fuzz->next<SkScalar>(), + fuzz->next<SkScalar>(), fuzz->next<SkScalar>(), + fuzz->next<SkScalar>()); break; case SkPath::Verb::kCubic_Verb: - if (!fuzz->next<SkScalar>(&a) || - !fuzz->next<SkScalar>(&b) || - !fuzz->next<SkScalar>(&c) || - !fuzz->next<SkScalar>(&d) || - !fuzz->next<SkScalar>(&e) || - !fuzz->next<SkScalar>(&f)) - return; - path->cubicTo(a, b, c, d, e, f); + path->cubicTo(fuzz->next<SkScalar>(), fuzz->next<SkScalar>(), + fuzz->next<SkScalar>(), fuzz->next<SkScalar>(), + fuzz->next<SkScalar>(), fuzz->next<SkScalar>()); break; case SkPath::Verb::kClose_Verb: @@ -74,13 +56,12 @@ void BuildPath(Fuzz* fuzz, DEF_FUZZ(Pathop, fuzz) { SkOpBuilder builder; - while (fuzz->remaining() >= sizeof(uint8_t)) { - SkPath path; - uint8_t op = fuzz->nextB(); - BuildPath(fuzz, &path, SkPath::Verb::kDone_Verb); - builder.add(path, static_cast<SkPathOp>(op % (kLastOp + 1))); - } + uint8_t stragglerOp = fuzz->next<uint8_t>(); + SkPath path; + + BuildPath(fuzz, &path, SkPath::Verb::kDone_Verb); + builder.add(path, static_cast<SkPathOp>(stragglerOp % (kLastOp + 1))); SkPath result; builder.resolve(&result); |