From 5bd98a244bb1ab1b3cad945e2fa1ce3dfd62d8cf Mon Sep 17 00:00:00 2001 From: kjlubick Date: Thu, 18 Feb 2016 06:27:38 -0800 Subject: 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 --- fuzz/fuzz.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'fuzz/fuzz.cpp') 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 #include #include @@ -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(); } +bool Fuzz::nextBool() { return nextB()&1; } uint32_t Fuzz::nextU() { return this->nextT(); } float Fuzz::nextF() { return this->nextT(); } + +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)); +} -- cgit v1.2.3