Coverage Report

Created: 2026-12-01 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zstd/lib/common/allocations.h
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
11
/* This file provides custom allocation primitives
12
 */
13
14
#define ZSTD_DEPS_NEED_MALLOC
15
#include "zstd_deps.h"   /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16
17
#include "compiler.h" /* MEM_STATIC */
18
#define ZSTD_STATIC_LINKING_ONLY
19
#include "../zstd.h" /* ZSTD_customMem */
20
21
#ifndef ZSTD_ALLOCATIONS_H
22
#define ZSTD_ALLOCATIONS_H
23
24
/* custom memory allocation functions */
25
26
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27
329k
{
28
329k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
329k
    return ZSTD_malloc(size);
31
329k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customMalloc
Unexecuted instantiation: pool.c:ZSTD_customMalloc
zstd_compress.c:ZSTD_customMalloc
Line
Count
Source
27
229k
{
28
229k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
229k
    return ZSTD_malloc(size);
31
229k
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_fast.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_lazy.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_ldm.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_opt.c:ZSTD_customMalloc
zstdmt_compress.c:ZSTD_customMalloc
Line
Count
Source
27
2.24k
{
28
2.24k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
2.24k
    return ZSTD_malloc(size);
31
2.24k
}
zstd_ddict.c:ZSTD_customMalloc
Line
Count
Source
27
60.4k
{
28
60.4k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
60.4k
    return ZSTD_malloc(size);
31
60.4k
}
zstd_decompress.c:ZSTD_customMalloc
Line
Count
Source
27
36.6k
{
28
36.6k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
36.6k
    return ZSTD_malloc(size);
31
36.6k
}
Unexecuted instantiation: fastcover.c:ZSTD_customMalloc
Unexecuted instantiation: zdict.c:ZSTD_customMalloc
32
33
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34
4.98k
{
35
4.98k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset */
37
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
38
39
0
        if (ptr == NULL) {
40
0
            return NULL;
41
0
        }
42
43
0
        ZSTD_memset(ptr, 0, size);
44
0
        return ptr;
45
0
    }
46
4.98k
    return ZSTD_calloc(1, size);
47
4.98k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customCalloc
pool.c:ZSTD_customCalloc
Line
Count
Source
34
1.35k
{
35
1.35k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset */
37
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
38
39
0
        if (ptr == NULL) {
40
0
            return NULL;
41
0
        }
42
43
0
        ZSTD_memset(ptr, 0, size);
44
0
        return ptr;
45
0
    }
46
1.35k
    return ZSTD_calloc(1, size);
47
1.35k
}
Unexecuted instantiation: zstd_compress.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_fast.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_lazy.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_ldm.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_opt.c:ZSTD_customCalloc
zstdmt_compress.c:ZSTD_customCalloc
Line
Count
Source
34
3.62k
{
35
3.62k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset */
37
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
38
39
0
        if (ptr == NULL) {
40
0
            return NULL;
41
0
        }
42
43
0
        ZSTD_memset(ptr, 0, size);
44
0
        return ptr;
45
0
    }
46
3.62k
    return ZSTD_calloc(1, size);
47
3.62k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_decompress.c:ZSTD_customCalloc
Unexecuted instantiation: fastcover.c:ZSTD_customCalloc
Unexecuted instantiation: zdict.c:ZSTD_customCalloc
48
49
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
50
630k
{
51
630k
    if (ptr!=NULL) {
52
334k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
334k
        else
55
334k
            ZSTD_free(ptr);
56
334k
    }
57
630k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customFree
pool.c:ZSTD_customFree
Line
Count
Source
50
1.35k
{
51
1.35k
    if (ptr!=NULL) {
52
1.35k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
1.35k
        else
55
1.35k
            ZSTD_free(ptr);
56
1.35k
    }
57
1.35k
}
zstd_compress.c:ZSTD_customFree
Line
Count
Source
50
473k
{
51
473k
    if (ptr!=NULL) {
52
229k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
229k
        else
55
229k
            ZSTD_free(ptr);
56
229k
    }
57
473k
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customFree
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customFree
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customFree
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customFree
Unexecuted instantiation: zstd_fast.c:ZSTD_customFree
Unexecuted instantiation: zstd_lazy.c:ZSTD_customFree
Unexecuted instantiation: zstd_ldm.c:ZSTD_customFree
Unexecuted instantiation: zstd_opt.c:ZSTD_customFree
zstdmt_compress.c:ZSTD_customFree
Line
Count
Source
50
9.40k
{
51
9.40k
    if (ptr!=NULL) {
52
5.86k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
5.86k
        else
55
5.86k
            ZSTD_free(ptr);
56
5.86k
    }
57
9.40k
}
zstd_ddict.c:ZSTD_customFree
Line
Count
Source
50
73.1k
{
51
73.1k
    if (ptr!=NULL) {
52
60.4k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
60.4k
        else
55
60.4k
            ZSTD_free(ptr);
56
60.4k
    }
57
73.1k
}
zstd_decompress.c:ZSTD_customFree
Line
Count
Source
50
73.2k
{
51
73.2k
    if (ptr!=NULL) {
52
36.6k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
36.6k
        else
55
36.6k
            ZSTD_free(ptr);
56
36.6k
    }
57
73.2k
}
Unexecuted instantiation: fastcover.c:ZSTD_customFree
Unexecuted instantiation: zdict.c:ZSTD_customFree
58
59
#endif /* ZSTD_ALLOCATIONS_H */