aboutsummaryrefslogtreecommitdiffhomepage
path: root/fuzz/fuzz.cpp
diff options
context:
space:
mode:
authorGravatar kjlubick <kjlubick@google.com>2016-02-18 06:27:38 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-18 06:27:39 -0800
commit5bd98a244bb1ab1b3cad945e2fa1ce3dfd62d8cf (patch)
treea00629eab90a2698fb7d9d3bbba64ab7773d0038 /fuzz/fuzz.cpp
parenta7b16858d51b5d9b7981087cadb1ff764632bf14 (diff)
Create ParsePath API fuzz
Diffstat (limited to 'fuzz/fuzz.cpp')
-rw-r--r--fuzz/fuzz.cpp30
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));
+}