blob: 1aad2152dfdae560f949874117c69eb3aab5969d [file] [log] [blame]
Kevin Lubickbc9a1a82018-09-17 14:46:57 -04001/*
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
9#include "Fuzz.h"
10#include "FuzzCommon.h"
11
12// UBSAN reminds us that bool can only legally hold 0 or 1.
13void Fuzz::next(bool* b) {
14 uint8_t n;
15 this->next(&n);
16 *b = (n & 1) == 1;
17}
18
19void Fuzz::next(SkImageFilter::CropRect* cropRect) {
20 SkRect rect;
21 uint8_t flags;
22 this->next(&rect);
23 this->nextRange(&flags, 0, 0xF);
24 *cropRect = SkImageFilter::CropRect(rect, flags);
25}
26
27void Fuzz::next(SkRegion* region) {
28 // See FuzzCommon.h
29 FuzzNiceRegion(this, region, 10);
30}
31
32void Fuzz::nextRange(float* f, float min, float max) {
33 this->next(f);
34 if (!std::isnormal(*f) && *f != 0.0f) {
35 // Don't deal with infinity or other strange floats.
36 *f = max;
37 }
38 *f = min + std::fmod(std::abs(*f), (max - min + 1));
39}