Coverage Report

Created: 2021-08-22 09:07

/src/skia/fuzz/Fuzz.cpp
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
3.91M
void Fuzz::next(bool* b) {
14
3.91M
  uint8_t n;
15
3.91M
  this->next(&n);
16
3.91M
  *b = (n & 1) == 1;
17
3.91M
}
18
19
841M
void Fuzz::nextBytes(void* n, size_t size) {
20
841M
    if ((fNextByte + size) > fBytes->size()) {
21
638M
        sk_bzero(n, size);
22
638M
        memcpy(n, fBytes->bytes() + fNextByte, fBytes->size() - fNextByte);
23
638M
        fNextByte = fBytes->size();
24
638M
        return;
25
638M
    }
26
202M
    memcpy(n, fBytes->bytes() + fNextByte, size);
27
202M
    fNextByte += size;
28
202M
}
29
30
48.6k
void Fuzz::next(SkRegion* region) {
31
    // See FuzzCommon.h
32
48.6k
    FuzzNiceRegion(this, region, 10);
33
48.6k
}
34
35
470k
void Fuzz::nextRange(float* f, float min, float max) {
36
470k
    this->next(f);
37
470k
    if (!std::isnormal(*f) && *f != 0.0f) {
38
        // Don't deal with infinity or other strange floats.
39
105k
        *f = max;
40
105k
    }
41
470k
    *f = min + std::fmod(std::abs(*f), (max - min + 1));
42
470k
}