blob: e7cf78a4b886abd1c97c65e11a219e7d865a354c [file] [log] [blame]
mtklein26379ca2016-01-21 09:25:32 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// Reminder of how to run:
9// $ env CC=afl-clang CXX=afl-clang++ ./gyp_skia
10// $ ninja -C out/Debug fuzz
11// $ afl-fuzz -i fuzz-in -o fuzz-out out/Debug/fuzz -n ScaleToSides -b @@
12// where you seed fuzz-in/ with one or more small files.
13
14#include "Fuzz.h"
15#include "SkScaleToSides.h"
16#include <cmath>
17
18DEF_FUZZ(ScaleToSides, fuzz) {
19 float radius1 = fuzz->nextF(),
20 radius2 = fuzz->nextF(),
21 width = fuzz->nextF();
mtklein26379ca2016-01-21 09:25:32 -080022
23 if (!std::isfinite(radius1) ||
24 !std::isfinite(radius2) ||
herb5e0883c2016-01-22 08:34:35 -080025 !std::isfinite(width) ||
26 radius1 <= 0.0f ||
27 radius2 <= 0.0f ||
28 width <= 0.0f)
mtklein26379ca2016-01-21 09:25:32 -080029 {
30 fuzz->signalBoring();
31 }
32
mtklein26379ca2016-01-21 09:25:32 -080033 double scale = (double)width / ((double)radius1 + (double)radius2);
herb5e0883c2016-01-22 08:34:35 -080034 if (scale >= 1.0 || scale <= 0.0) {
mtklein26379ca2016-01-21 09:25:32 -080035 fuzz->signalBoring();
36 }
herb5e0883c2016-01-22 08:34:35 -080037 SkDebugf("%g %g %g %g\n", radius1, radius2, width, scale);
herb97293c62016-01-22 11:58:55 -080038 SkScaleToSides::AdjustRadii(width, scale, &radius1, &radius2);
mtklein26379ca2016-01-21 09:25:32 -080039
40 // TODO(mtklein): add fuzz->keepResult()
41 volatile float junk = 0.0f;
42 junk *= radius1;
43 junk *= radius2;
44}