Line | Count | Source |
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 | | |
9 | | #include "fuzz/Fuzz.h" |
10 | | #include "fuzz/FuzzCommon.h" |
11 | | |
12 | | // UBSAN reminds us that bool can only legally hold 0 or 1. |
13 | 831k | void Fuzz::next(bool* b) { |
14 | 831k | uint8_t n; |
15 | 831k | this->next(&n); |
16 | 831k | *b = (n & 1) == 1; |
17 | 831k | } |
18 | | |
19 | 315M | void Fuzz::nextBytes(void* n, size_t size) { |
20 | 315M | if ((fNextByte + size) > fSize) { |
21 | 275M | sk_bzero(n, size); |
22 | 275M | memcpy(n, fData + fNextByte, fSize - fNextByte); |
23 | 275M | fNextByte = fSize; |
24 | 275M | return; |
25 | 275M | } |
26 | 39.7M | memcpy(n, fData + fNextByte, size); |
27 | 39.7M | fNextByte += size; |
28 | 39.7M | } |
29 | | |
30 | 11.9k | void Fuzz::next(SkRegion* region) { |
31 | | // See FuzzCommon.h |
32 | 11.9k | FuzzNiceRegion(this, region, 10); |
33 | 11.9k | } |
34 | | |
35 | 149k | void Fuzz::nextRange(float* f, float min, float max) { |
36 | 149k | this->next(f); |
37 | 149k | if (!std::isnormal(*f) && *f != 0.0f) { |
38 | | // Don't deal with infinity or other strange floats. |
39 | 17.1k | *f = max; |
40 | 17.1k | } |
41 | 149k | *f = min + std::fmod(std::abs(*f), (max - min + 1)); |
42 | 149k | } |