Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Utilities/cmliblzma/liblzma/delta/delta_common.c
Line
Count
Source
1
// SPDX-License-Identifier: 0BSD
2
3
///////////////////////////////////////////////////////////////////////////////
4
//
5
/// \file       delta_common.c
6
/// \brief      Common stuff for Delta encoder and decoder
7
//
8
//  Author:     Lasse Collin
9
//
10
///////////////////////////////////////////////////////////////////////////////
11
12
#include "delta_common.h"
13
#include "delta_private.h"
14
15
16
static void
17
delta_coder_end(void *coder_ptr, const lzma_allocator *allocator)
18
322
{
19
322
  lzma_delta_coder *coder = coder_ptr;
20
322
  lzma_next_end(&coder->next, allocator);
21
322
  lzma_free(coder, allocator);
22
322
  return;
23
322
}
24
25
26
extern lzma_ret
27
lzma_delta_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
28
    const lzma_filter_info *filters)
29
1.27k
{
30
  // Allocate memory for the decoder if needed.
31
1.27k
  lzma_delta_coder *coder = next->coder;
32
1.27k
  if (coder == NULL) {
33
322
    coder = lzma_alloc(sizeof(lzma_delta_coder), allocator);
34
322
    if (coder == NULL)
35
0
      return LZMA_MEM_ERROR;
36
37
322
    next->coder = coder;
38
39
    // End function is the same for encoder and decoder.
40
322
    next->end = &delta_coder_end;
41
322
    coder->next = LZMA_NEXT_CODER_INIT;
42
322
  }
43
44
  // Validate the options.
45
1.27k
  if (lzma_delta_coder_memusage(filters[0].options) == UINT64_MAX)
46
0
    return LZMA_OPTIONS_ERROR;
47
48
  // Set the delta distance.
49
1.27k
  const lzma_options_delta *opt = filters[0].options;
50
1.27k
  coder->distance = opt->dist;
51
52
  // Initialize the rest of the variables.
53
1.27k
  coder->pos = 0;
54
1.27k
  memzero(coder->history, LZMA_DELTA_DIST_MAX);
55
56
  // Initialize the next decoder in the chain, if any.
57
1.27k
  return lzma_next_filter_init(&coder->next, allocator, filters + 1);
58
1.27k
}
59
60
61
extern uint64_t
62
lzma_delta_coder_memusage(const void *options)
63
2.54k
{
64
2.54k
  const lzma_options_delta *opt = options;
65
66
2.54k
  if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE
67
2.54k
      || opt->dist < LZMA_DELTA_DIST_MIN
68
2.54k
      || opt->dist > LZMA_DELTA_DIST_MAX)
69
0
    return UINT64_MAX;
70
71
2.54k
  return sizeof(lzma_delta_coder);
72
2.54k
}