Coverage Report

Created: 2026-11-12 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zstd/tests/fuzz/fuzz_helpers.c
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under both the BSD-style license (found in the
6
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
 * in the COPYING file in the root directory of this source tree).
8
 * You may select, at your option, one of the above-listed licenses.
9
 */
10
#include "fuzz_helpers.h"
11
12
#include <stddef.h>
13
#include <stdlib.h>
14
#include <string.h>
15
16
void* FUZZ_malloc(size_t size)
17
1.02M
{
18
1.02M
    if (size > 0) {
19
991k
        void* const mem = malloc(size);
20
991k
        FUZZ_ASSERT(mem);
21
991k
        return mem;
22
991k
    }
23
34.8k
    return NULL;
24
1.02M
}
25
26
void* FUZZ_malloc_rand(size_t size, FUZZ_dataProducer_t *producer)
27
1
{
28
1
    if (size > 0) {
29
1
        void* const mem = malloc(size);
30
1
        FUZZ_ASSERT(mem);
31
1
        return mem;
32
1
    } else {
33
0
        uintptr_t ptr = 0;
34
        /* Return junk pointer 50% of the time */
35
0
        if (FUZZ_dataProducer_uint32Range(producer, 0, 1))
36
0
            ptr += FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
37
0
        return (void*)ptr;
38
0
    }
39
1
}
40
41
int FUZZ_memcmp(void const* lhs, void const* rhs, size_t size)
42
213k
{
43
213k
    if (size == 0) {
44
1.06k
        return 0;
45
1.06k
    }
46
212k
    return memcmp(lhs, rhs, size);
47
213k
}