diff options
author | kjlubick <kjlubick@google.com> | 2016-02-18 06:27:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-18 06:27:39 -0800 |
commit | 5bd98a244bb1ab1b3cad945e2fa1ce3dfd62d8cf (patch) | |
tree | a00629eab90a2698fb7d9d3bbba64ab7773d0038 /fuzz/fuzz.cpp | |
parent | a7b16858d51b5d9b7981087cadb1ff764632bf14 (diff) |
Create ParsePath API fuzz
This is based on https://codereview.chromium.org/1675053002
BUG=skia:4438
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1702383003
Review URL: https://codereview.chromium.org/1702383003
Diffstat (limited to 'fuzz/fuzz.cpp')
-rw-r--r-- | fuzz/fuzz.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp index 596000d408..dce9c8adbb 100644 --- a/fuzz/fuzz.cpp +++ b/fuzz/fuzz.cpp @@ -17,6 +17,7 @@ #include "SkPicture.h" #include "SkStream.h" +#include <cmath> #include <signal.h> #include <stdlib.h> @@ -114,8 +115,8 @@ static void dump_png(SkBitmap bitmap) { int fuzz_img(SkData* bytes, uint8_t scale, uint8_t mode) { // We can scale 1x, 2x, 4x, 8x, 16x scale = scale % 5; - float fscale = pow(2.0f, scale); - SkDebugf("Scaling factor: %d\n", fscale); + float fscale = (float)pow(2.0f, scale); + SkDebugf("Scaling factor: %f\n", fscale); // We have 4 different modes of decoding, just like DM. mode = mode % 4; @@ -393,6 +394,31 @@ T Fuzz::nextT() { } uint8_t Fuzz::nextB() { return this->nextT<uint8_t >(); } +bool Fuzz::nextBool() { return nextB()&1; } uint32_t Fuzz::nextU() { return this->nextT<uint32_t>(); } float Fuzz::nextF() { return this->nextT<float >(); } + +uint32_t Fuzz::nextRangeU(uint32_t min, uint32_t max) { + if (min > max) { + SkDebugf("Check mins and maxes (%d, %d)\n", min, max); + this->signalBoring(); + } + uint32_t range = max - min + 1; + if (0 == range) { + return this->nextU(); + } else { + return min + this->nextU() % range; + } +} +float Fuzz::nextRangeF(float min, float max) { + if (min > max) { + SkDebugf("Check mins and maxes (%f, %f)\n", min, max); + this->signalBoring(); + } + float f = std::abs(this->nextF()); + if (!std::isnormal(f) && f != 0.0) { + this->signalBoring(); + } + return min + fmod(f, (max - min + 1)); +} |