Coverage Report

Created: 2024-09-14 07:19

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