mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | DEF_FUZZ(ScaleToSides, fuzz) { |
Kevin Lubick | 416b248 | 2016-11-10 16:17:49 -0500 | [diff] [blame] | 19 | float radius1, radius2, width; |
| 20 | fuzz->next(&radius1, &radius2, &width); |
mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 21 | |
| 22 | if (!std::isfinite(radius1) || |
| 23 | !std::isfinite(radius2) || |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 24 | !std::isfinite(width) || |
| 25 | radius1 <= 0.0f || |
| 26 | radius2 <= 0.0f || |
| 27 | width <= 0.0f) |
mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 28 | { |
Kevin Lubick | 2f535ce | 2016-11-01 15:01:12 -0400 | [diff] [blame] | 29 | return; |
mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 30 | } |
| 31 | |
mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 32 | double scale = (double)width / ((double)radius1 + (double)radius2); |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 33 | if (scale >= 1.0 || scale <= 0.0) { |
Kevin Lubick | 2f535ce | 2016-11-01 15:01:12 -0400 | [diff] [blame] | 34 | return; |
mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 35 | } |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 36 | SkDebugf("%g %g %g %g\n", radius1, radius2, width, scale); |
herb | 97293c6 | 2016-01-22 11:58:55 -0800 | [diff] [blame] | 37 | SkScaleToSides::AdjustRadii(width, scale, &radius1, &radius2); |
mtklein | 26379ca | 2016-01-21 09:25:32 -0800 | [diff] [blame] | 38 | |
| 39 | // TODO(mtklein): add fuzz->keepResult() |
| 40 | volatile float junk = 0.0f; |
| 41 | junk *= radius1; |
| 42 | junk *= radius2; |
| 43 | } |