Coverage Report

Created: 2026-12-01 06:40

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
214k
{
28
214k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
214k
    return ZSTD_malloc(size);
31
214k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customMalloc
Unexecuted instantiation: pool.c:ZSTD_customMalloc
zstd_compress.c:ZSTD_customMalloc
Line
Count
Source
27
95.6k
{
28
95.6k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
95.6k
    return ZSTD_malloc(size);
31
95.6k
}
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
41.3k
{
28
41.3k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
41.3k
    return ZSTD_malloc(size);
31
41.3k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_customMalloc
zstd_decompress.c:ZSTD_customMalloc
Line
Count
Source
27
77.5k
{
28
77.5k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
77.5k
    return ZSTD_malloc(size);
31
77.5k
}
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
138k
{
35
138k
    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
138k
    return ZSTD_calloc(1, size);
47
138k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customCalloc
pool.c:ZSTD_customCalloc
Line
Count
Source
34
37.6k
{
35
37.6k
    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
37.6k
    return ZSTD_calloc(1, size);
47
37.6k
}
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
100k
{
35
100k
    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
100k
    return ZSTD_calloc(1, size);
47
100k
}
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
642k
{
51
642k
    if (ptr!=NULL) {
52
352k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
352k
        else
55
352k
            ZSTD_free(ptr);
56
352k
    }
57
642k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customFree
pool.c:ZSTD_customFree
Line
Count
Source
50
37.6k
{
51
37.6k
    if (ptr!=NULL) {
52
37.6k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
37.6k
        else
55
37.6k
            ZSTD_free(ptr);
56
37.6k
    }
57
37.6k
}
zstd_compress.c:ZSTD_customFree
Line
Count
Source
50
249k
{
51
249k
    if (ptr!=NULL) {
52
95.6k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
95.6k
        else
55
95.6k
            ZSTD_free(ptr);
56
95.6k
    }
57
249k
}
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
239k
{
51
239k
    if (ptr!=NULL) {
52
142k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
142k
        else
55
142k
            ZSTD_free(ptr);
56
142k
    }
57
239k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_customFree
zstd_decompress.c:ZSTD_customFree
Line
Count
Source
50
116k
{
51
116k
    if (ptr!=NULL) {
52
77.5k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
77.5k
        else
55
77.5k
            ZSTD_free(ptr);
56
77.5k
    }
57
116k
}
Unexecuted instantiation: fastcover.c:ZSTD_customFree
Unexecuted instantiation: zdict.c:ZSTD_customFree
58
59
#endif /* ZSTD_ALLOCATIONS_H */