Coverage Report

Created: 2025-08-11 08:01

/src/xz/src/liblzma/common/index.h
Line
Count
Source
1
// SPDX-License-Identifier: 0BSD
2
3
///////////////////////////////////////////////////////////////////////////////
4
//
5
/// \file       index.h
6
/// \brief      Handling of Index
7
/// \note       This header file does not include common.h or lzma.h because
8
///             this file is needed by both liblzma internally and by the
9
///             tests. Including common.h will include and define many things
10
///             the tests do not need and prevents issues with header file
11
///             include order. This way, if lzma.h or common.h are not
12
///             included before this file it will break on every OS instead
13
///             of causing more subtle errors.
14
//
15
//  Author:     Lasse Collin
16
//
17
///////////////////////////////////////////////////////////////////////////////
18
19
#ifndef LZMA_INDEX_H
20
#define LZMA_INDEX_H
21
22
23
/// Minimum Unpadded Size
24
2.10k
#define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
25
26
/// Maximum Unpadded Size
27
8.13k
#define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
28
29
/// Index Indicator based on xz specification
30
11.4k
#define INDEX_INDICATOR 0
31
32
33
/// Get the size of the Index Padding field. This is needed by Index encoder
34
/// and decoder, but applications should have no use for this.
35
extern uint32_t lzma_index_padding_size(const lzma_index *i);
36
37
38
/// Set for how many Records to allocate memory the next time
39
/// lzma_index_append() needs to allocate space for a new Record.
40
/// This is used only by the Index decoder.
41
extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
42
43
44
/// Round the variable-length integer to the next multiple of four.
45
static inline lzma_vli
46
vli_ceil4(lzma_vli vli)
47
14.0k
{
48
14.0k
  assert(vli <= UNPADDED_SIZE_MAX);
49
14.0k
  return (vli + 3) & ~LZMA_VLI_C(3);
50
14.0k
}
Unexecuted instantiation: stream_decoder.c:vli_ceil4
Unexecuted instantiation: block_util.c:vli_ceil4
index.c:vli_ceil4
Line
Count
Source
47
12.8k
{
48
12.8k
  assert(vli <= UNPADDED_SIZE_MAX);
49
12.8k
  return (vli + 3) & ~LZMA_VLI_C(3);
50
12.8k
}
Unexecuted instantiation: index_encoder.c:vli_ceil4
index_hash.c:vli_ceil4
Line
Count
Source
47
1.18k
{
48
1.18k
  assert(vli <= UNPADDED_SIZE_MAX);
49
1.18k
  return (vli + 3) & ~LZMA_VLI_C(3);
50
1.18k
}
51
52
53
/// Calculate the size of the Index field excluding Index Padding
54
static inline lzma_vli
55
index_size_unpadded(lzma_vli count, lzma_vli index_list_size)
56
8.90k
{
57
  // Index Indicator + Number of Records + List of Records + CRC32
58
8.90k
  return 1 + lzma_vli_size(count) + index_list_size + 4;
59
8.90k
}
Unexecuted instantiation: stream_decoder.c:index_size_unpadded
Unexecuted instantiation: block_util.c:index_size_unpadded
index.c:index_size_unpadded
Line
Count
Source
56
8.03k
{
57
  // Index Indicator + Number of Records + List of Records + CRC32
58
8.03k
  return 1 + lzma_vli_size(count) + index_list_size + 4;
59
8.03k
}
Unexecuted instantiation: index_encoder.c:index_size_unpadded
index_hash.c:index_size_unpadded
Line
Count
Source
56
870
{
57
  // Index Indicator + Number of Records + List of Records + CRC32
58
870
  return 1 + lzma_vli_size(count) + index_list_size + 4;
59
870
}
60
61
62
/// Calculate the size of the Index field including Index Padding
63
static inline lzma_vli
64
index_size(lzma_vli count, lzma_vli index_list_size)
65
7.15k
{
66
7.15k
  return vli_ceil4(index_size_unpadded(count, index_list_size));
67
7.15k
}
Unexecuted instantiation: stream_decoder.c:index_size
Unexecuted instantiation: block_util.c:index_size
index.c:index_size
Line
Count
Source
65
6.42k
{
66
6.42k
  return vli_ceil4(index_size_unpadded(count, index_list_size));
67
6.42k
}
Unexecuted instantiation: index_encoder.c:index_size
index_hash.c:index_size
Line
Count
Source
65
731
{
66
731
  return vli_ceil4(index_size_unpadded(count, index_list_size));
67
731
}
68
69
70
/// Calculate the total size of the Stream
71
static inline lzma_vli
72
index_stream_size(lzma_vli blocks_size,
73
    lzma_vli count, lzma_vli index_list_size)
74
360
{
75
360
  return LZMA_STREAM_HEADER_SIZE + blocks_size
76
360
      + index_size(count, index_list_size)
77
360
      + LZMA_STREAM_HEADER_SIZE;
78
360
}
Unexecuted instantiation: stream_decoder.c:index_stream_size
Unexecuted instantiation: block_util.c:index_stream_size
Unexecuted instantiation: index.c:index_stream_size
Unexecuted instantiation: index_encoder.c:index_stream_size
index_hash.c:index_stream_size
Line
Count
Source
74
360
{
75
360
  return LZMA_STREAM_HEADER_SIZE + blocks_size
76
360
      + index_size(count, index_list_size)
77
360
      + LZMA_STREAM_HEADER_SIZE;
78
360
}
79
80
#endif