Coverage Report

Created: 2026-08-31 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/deflate_p.h
Line
Count
Source
1
/* deflate_p.h -- Private inline functions and macros shared with more than
2
 *                one deflate method
3
 *
4
 * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
5
 * For conditions of distribution and use, see copyright notice in zlib.h
6
 *
7
 */
8
9
#ifndef DEFLATE_P_H
10
#define DEFLATE_P_H
11
12
#include "functable.h"
13
#include "fallback_builtins.h"
14
#include "zmemory.h"
15
16
/* Forward declare common non-inlined functions declared in deflate.c */
17
18
#ifdef ZLIB_DEBUG
19
/* ===========================================================================
20
 * Check that the match at match_start is indeed a match.
21
 */
22
static inline void check_match(deflate_state *s, uint32_t start, uint32_t match, uint32_t length) {
23
    /* check that the match length is valid*/
24
    if (length < STD_MIN_MATCH || length > STD_MAX_MATCH) {
25
        fprintf(stderr, " start %u, match %u, length %u\n", start, match, length);
26
        z_error("invalid match length");
27
    }
28
    /* check that the match isn't at the same position as the start string */
29
    if (match == start) {
30
        fprintf(stderr, " start %u, match %u, length %u\n", start, match, length);
31
        z_error("invalid match position");
32
    }
33
    /* check that the match is indeed a match */
34
    if (memcmp(s->window + match, s->window + start, length) != 0) {
35
        int32_t i = 0;
36
        fprintf(stderr, " start %u, match %u, length %u\n", start, match, length);
37
        do {
38
            fprintf(stderr, "  %03d: match [%02x] start [%02x]\n", i++,
39
                s->window[match++], s->window[start++]);
40
        } while (--length != 0);
41
        z_error("invalid match");
42
    }
43
    if (z_verbose > 1) {
44
        fprintf(stderr, "\\[%u,%u]", start-match, length);
45
        do {
46
            putc(s->window[start++], stderr);
47
        } while (--length != 0);
48
    }
49
}
50
#else
51
#define check_match(s, start, match, length)
52
#endif
53
54
Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm);
55
56
/* ===========================================================================
57
 * Save the match info and tally the frequency counts. Return true if
58
 * the current block must be flushed.
59
 */
60
61
extern Z_INTERNAL const unsigned char zng_length_code[];
62
extern Z_INTERNAL const unsigned char zng_dist_code[];
63
64
898M
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
65
    /* c is the unmatched char */
66
898M
    unsigned int sym_next = s->sym_next;
67
#ifdef LIT_MEM
68
    s->d_buf[sym_next] = 0;
69
    s->l_buf[sym_next] = c;
70
    s->sym_next = sym_next + 1;
71
#else
72
898M
#  if OPTIMAL_CMP >= 32
73
898M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16));
74
#  else
75
    s->sym_buf[sym_next] = 0;
76
    s->sym_buf[sym_next+1] = 0;
77
    s->sym_buf[sym_next+2] = c;
78
#  endif
79
898M
    s->sym_next = sym_next + 3;
80
898M
#endif
81
898M
    s->dyn_ltree[c].Freq++;
82
898M
    Tracevv((stderr, "%c", c));
83
898M
    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
84
898M
    return (s->sym_next == s->sym_end);
85
898M
}
Unexecuted instantiation: deflate.c:zng_tr_tally_lit
deflate_fast.c:zng_tr_tally_lit
Line
Count
Source
64
18.5M
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
65
    /* c is the unmatched char */
66
18.5M
    unsigned int sym_next = s->sym_next;
67
#ifdef LIT_MEM
68
    s->d_buf[sym_next] = 0;
69
    s->l_buf[sym_next] = c;
70
    s->sym_next = sym_next + 1;
71
#else
72
18.5M
#  if OPTIMAL_CMP >= 32
73
18.5M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16));
74
#  else
75
    s->sym_buf[sym_next] = 0;
76
    s->sym_buf[sym_next+1] = 0;
77
    s->sym_buf[sym_next+2] = c;
78
#  endif
79
18.5M
    s->sym_next = sym_next + 3;
80
18.5M
#endif
81
18.5M
    s->dyn_ltree[c].Freq++;
82
18.5M
    Tracevv((stderr, "%c", c));
83
18.5M
    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
84
18.5M
    return (s->sym_next == s->sym_end);
85
18.5M
}
deflate_huff.c:zng_tr_tally_lit
Line
Count
Source
64
100M
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
65
    /* c is the unmatched char */
66
100M
    unsigned int sym_next = s->sym_next;
67
#ifdef LIT_MEM
68
    s->d_buf[sym_next] = 0;
69
    s->l_buf[sym_next] = c;
70
    s->sym_next = sym_next + 1;
71
#else
72
100M
#  if OPTIMAL_CMP >= 32
73
100M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16));
74
#  else
75
    s->sym_buf[sym_next] = 0;
76
    s->sym_buf[sym_next+1] = 0;
77
    s->sym_buf[sym_next+2] = c;
78
#  endif
79
100M
    s->sym_next = sym_next + 3;
80
100M
#endif
81
100M
    s->dyn_ltree[c].Freq++;
82
100M
    Tracevv((stderr, "%c", c));
83
100M
    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
84
100M
    return (s->sym_next == s->sym_end);
85
100M
}
deflate_medium.c:zng_tr_tally_lit
Line
Count
Source
64
561M
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
65
    /* c is the unmatched char */
66
561M
    unsigned int sym_next = s->sym_next;
67
#ifdef LIT_MEM
68
    s->d_buf[sym_next] = 0;
69
    s->l_buf[sym_next] = c;
70
    s->sym_next = sym_next + 1;
71
#else
72
561M
#  if OPTIMAL_CMP >= 32
73
561M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16));
74
#  else
75
    s->sym_buf[sym_next] = 0;
76
    s->sym_buf[sym_next+1] = 0;
77
    s->sym_buf[sym_next+2] = c;
78
#  endif
79
561M
    s->sym_next = sym_next + 3;
80
561M
#endif
81
561M
    s->dyn_ltree[c].Freq++;
82
561M
    Tracevv((stderr, "%c", c));
83
561M
    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
84
561M
    return (s->sym_next == s->sym_end);
85
561M
}
Unexecuted instantiation: deflate_quick.c:zng_tr_tally_lit
deflate_rle.c:zng_tr_tally_lit
Line
Count
Source
64
49.8M
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
65
    /* c is the unmatched char */
66
49.8M
    unsigned int sym_next = s->sym_next;
67
#ifdef LIT_MEM
68
    s->d_buf[sym_next] = 0;
69
    s->l_buf[sym_next] = c;
70
    s->sym_next = sym_next + 1;
71
#else
72
49.8M
#  if OPTIMAL_CMP >= 32
73
49.8M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16));
74
#  else
75
    s->sym_buf[sym_next] = 0;
76
    s->sym_buf[sym_next+1] = 0;
77
    s->sym_buf[sym_next+2] = c;
78
#  endif
79
49.8M
    s->sym_next = sym_next + 3;
80
49.8M
#endif
81
49.8M
    s->dyn_ltree[c].Freq++;
82
49.8M
    Tracevv((stderr, "%c", c));
83
49.8M
    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
84
49.8M
    return (s->sym_next == s->sym_end);
85
49.8M
}
deflate_slow.c:zng_tr_tally_lit
Line
Count
Source
64
169M
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
65
    /* c is the unmatched char */
66
169M
    unsigned int sym_next = s->sym_next;
67
#ifdef LIT_MEM
68
    s->d_buf[sym_next] = 0;
69
    s->l_buf[sym_next] = c;
70
    s->sym_next = sym_next + 1;
71
#else
72
169M
#  if OPTIMAL_CMP >= 32
73
169M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE((uint32_t)c << 16));
74
#  else
75
    s->sym_buf[sym_next] = 0;
76
    s->sym_buf[sym_next+1] = 0;
77
    s->sym_buf[sym_next+2] = c;
78
#  endif
79
169M
    s->sym_next = sym_next + 3;
80
169M
#endif
81
169M
    s->dyn_ltree[c].Freq++;
82
169M
    Tracevv((stderr, "%c", c));
83
169M
    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
84
169M
    return (s->sym_next == s->sym_end);
85
169M
}
Unexecuted instantiation: deflate_stored.c:zng_tr_tally_lit
Unexecuted instantiation: trees.c:zng_tr_tally_lit
86
87
32.0M
static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) {
88
    /* dist: distance of matched string */
89
    /* len: match length-STD_MIN_MATCH */
90
32.0M
    unsigned int sym_next = s->sym_next;
91
#ifdef LIT_MEM
92
    Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
93
    Assert(len <= UINT8_MAX, "len should fit in uint8_t");
94
    s->d_buf[sym_next] = (uint16_t)dist;
95
    s->l_buf[sym_next] = (uint8_t)len;
96
    s->sym_next = sym_next + 1;
97
#else
98
32.0M
#  if OPTIMAL_CMP >= 32
99
32.0M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16)));
100
#  else
101
    s->sym_buf[sym_next] = (uint8_t)(dist);
102
    s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8);
103
    s->sym_buf[sym_next+2] = (uint8_t)len;
104
#  endif
105
32.0M
    s->sym_next = sym_next + 3;
106
32.0M
#endif
107
32.0M
    dist--;
108
32.0M
    Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES,
109
32.0M
        "zng_tr_tally: bad match");
110
111
32.0M
    s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++;
112
32.0M
    s->dyn_dtree[d_code(dist)].Freq++;
113
32.0M
    return (s->sym_next == s->sym_end);
114
32.0M
}
Unexecuted instantiation: deflate.c:zng_tr_tally_dist
deflate_fast.c:zng_tr_tally_dist
Line
Count
Source
87
1.18M
static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) {
88
    /* dist: distance of matched string */
89
    /* len: match length-STD_MIN_MATCH */
90
1.18M
    unsigned int sym_next = s->sym_next;
91
#ifdef LIT_MEM
92
    Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
93
    Assert(len <= UINT8_MAX, "len should fit in uint8_t");
94
    s->d_buf[sym_next] = (uint16_t)dist;
95
    s->l_buf[sym_next] = (uint8_t)len;
96
    s->sym_next = sym_next + 1;
97
#else
98
1.18M
#  if OPTIMAL_CMP >= 32
99
1.18M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16)));
100
#  else
101
    s->sym_buf[sym_next] = (uint8_t)(dist);
102
    s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8);
103
    s->sym_buf[sym_next+2] = (uint8_t)len;
104
#  endif
105
1.18M
    s->sym_next = sym_next + 3;
106
1.18M
#endif
107
1.18M
    dist--;
108
1.18M
    Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES,
109
1.18M
        "zng_tr_tally: bad match");
110
111
1.18M
    s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++;
112
1.18M
    s->dyn_dtree[d_code(dist)].Freq++;
113
1.18M
    return (s->sym_next == s->sym_end);
114
1.18M
}
Unexecuted instantiation: deflate_huff.c:zng_tr_tally_dist
deflate_medium.c:zng_tr_tally_dist
Line
Count
Source
87
15.1M
static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) {
88
    /* dist: distance of matched string */
89
    /* len: match length-STD_MIN_MATCH */
90
15.1M
    unsigned int sym_next = s->sym_next;
91
#ifdef LIT_MEM
92
    Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
93
    Assert(len <= UINT8_MAX, "len should fit in uint8_t");
94
    s->d_buf[sym_next] = (uint16_t)dist;
95
    s->l_buf[sym_next] = (uint8_t)len;
96
    s->sym_next = sym_next + 1;
97
#else
98
15.1M
#  if OPTIMAL_CMP >= 32
99
15.1M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16)));
100
#  else
101
    s->sym_buf[sym_next] = (uint8_t)(dist);
102
    s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8);
103
    s->sym_buf[sym_next+2] = (uint8_t)len;
104
#  endif
105
15.1M
    s->sym_next = sym_next + 3;
106
15.1M
#endif
107
15.1M
    dist--;
108
15.1M
    Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES,
109
15.1M
        "zng_tr_tally: bad match");
110
111
15.1M
    s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++;
112
15.1M
    s->dyn_dtree[d_code(dist)].Freq++;
113
15.1M
    return (s->sym_next == s->sym_end);
114
15.1M
}
Unexecuted instantiation: deflate_quick.c:zng_tr_tally_dist
deflate_rle.c:zng_tr_tally_dist
Line
Count
Source
87
3.51M
static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) {
88
    /* dist: distance of matched string */
89
    /* len: match length-STD_MIN_MATCH */
90
3.51M
    unsigned int sym_next = s->sym_next;
91
#ifdef LIT_MEM
92
    Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
93
    Assert(len <= UINT8_MAX, "len should fit in uint8_t");
94
    s->d_buf[sym_next] = (uint16_t)dist;
95
    s->l_buf[sym_next] = (uint8_t)len;
96
    s->sym_next = sym_next + 1;
97
#else
98
3.51M
#  if OPTIMAL_CMP >= 32
99
3.51M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16)));
100
#  else
101
    s->sym_buf[sym_next] = (uint8_t)(dist);
102
    s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8);
103
    s->sym_buf[sym_next+2] = (uint8_t)len;
104
#  endif
105
3.51M
    s->sym_next = sym_next + 3;
106
3.51M
#endif
107
3.51M
    dist--;
108
3.51M
    Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES,
109
3.51M
        "zng_tr_tally: bad match");
110
111
3.51M
    s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++;
112
3.51M
    s->dyn_dtree[d_code(dist)].Freq++;
113
3.51M
    return (s->sym_next == s->sym_end);
114
3.51M
}
deflate_slow.c:zng_tr_tally_dist
Line
Count
Source
87
12.2M
static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t len) {
88
    /* dist: distance of matched string */
89
    /* len: match length-STD_MIN_MATCH */
90
12.2M
    unsigned int sym_next = s->sym_next;
91
#ifdef LIT_MEM
92
    Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
93
    Assert(len <= UINT8_MAX, "len should fit in uint8_t");
94
    s->d_buf[sym_next] = (uint16_t)dist;
95
    s->l_buf[sym_next] = (uint8_t)len;
96
    s->sym_next = sym_next + 1;
97
#else
98
12.2M
#  if OPTIMAL_CMP >= 32
99
12.2M
    zng_memwrite_4(&s->sym_buf[sym_next], Z_U32_TO_LE(dist | ((uint32_t)len << 16)));
100
#  else
101
    s->sym_buf[sym_next] = (uint8_t)(dist);
102
    s->sym_buf[sym_next+1] = (uint8_t)(dist >> 8);
103
    s->sym_buf[sym_next+2] = (uint8_t)len;
104
#  endif
105
12.2M
    s->sym_next = sym_next + 3;
106
12.2M
#endif
107
12.2M
    dist--;
108
12.2M
    Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES,
109
12.2M
        "zng_tr_tally: bad match");
110
111
12.2M
    s->dyn_ltree[zng_length_code[len] + LITERALS + 1].Freq++;
112
12.2M
    s->dyn_dtree[d_code(dist)].Freq++;
113
12.2M
    return (s->sym_next == s->sym_end);
114
12.2M
}
Unexecuted instantiation: deflate_stored.c:zng_tr_tally_dist
Unexecuted instantiation: trees.c:zng_tr_tally_dist
115
116
/* =========================================================================
117
 * Flush as much pending output as possible. All deflate() output, except for some
118
 * deflate_stored() output, goes through this function so some applications may wish to
119
 * modify it to avoid allocating a large strm->next_out buffer and copying into it.
120
 * See also read_buf().
121
 */
122
113M
Z_FORCEINLINE static void flush_pending_inline(PREFIX3(stream) *strm) {
123
113M
    uint32_t len;
124
113M
    deflate_state *s = strm->state;
125
126
113M
    zng_tr_flush_bits(s);
127
113M
    len = MIN(s->pending, strm->avail_out);
128
113M
    if (len == 0)
129
17.1k
        return;
130
131
113M
    Tracev((stderr, "[FLUSH]"));
132
113M
    memcpy(strm->next_out, s->pending_out, len);
133
113M
    strm->next_out  += len;
134
113M
    s->pending_out  += len;
135
113M
    strm->total_out += len;
136
113M
    strm->avail_out -= len;
137
113M
    s->pending      -= len;
138
113M
    if (s->pending == 0)
139
270k
        s->pending_out = s->pending_buf;
140
113M
}
deflate.c:flush_pending_inline
Line
Count
Source
122
113M
Z_FORCEINLINE static void flush_pending_inline(PREFIX3(stream) *strm) {
123
113M
    uint32_t len;
124
113M
    deflate_state *s = strm->state;
125
126
113M
    zng_tr_flush_bits(s);
127
113M
    len = MIN(s->pending, strm->avail_out);
128
113M
    if (len == 0)
129
17.1k
        return;
130
131
113M
    Tracev((stderr, "[FLUSH]"));
132
113M
    memcpy(strm->next_out, s->pending_out, len);
133
113M
    strm->next_out  += len;
134
113M
    s->pending_out  += len;
135
113M
    strm->total_out += len;
136
113M
    strm->avail_out -= len;
137
113M
    s->pending      -= len;
138
113M
    if (s->pending == 0)
139
270k
        s->pending_out = s->pending_buf;
140
113M
}
Unexecuted instantiation: deflate_fast.c:flush_pending_inline
Unexecuted instantiation: deflate_huff.c:flush_pending_inline
Unexecuted instantiation: deflate_medium.c:flush_pending_inline
Unexecuted instantiation: deflate_quick.c:flush_pending_inline
Unexecuted instantiation: deflate_rle.c:flush_pending_inline
Unexecuted instantiation: deflate_slow.c:flush_pending_inline
Unexecuted instantiation: deflate_stored.c:flush_pending_inline
Unexecuted instantiation: trees.c:flush_pending_inline
141
142
/* ===========================================================================
143
 * Reverse the first len bits of a code using bit manipulation
144
 */
145
19.2M
Z_FORCEINLINE static uint16_t bi_reverse(uint16_t code, int len) {
146
    /* code: the value to invert */
147
    /* len: its bit length */
148
19.2M
    Assert(len >= 1 && len <= 15, "code length must be 1-15");
149
19.2M
    return zng_bitreverse16(code) >> (16 - len);
150
19.2M
}
Unexecuted instantiation: deflate.c:bi_reverse
Unexecuted instantiation: deflate_fast.c:bi_reverse
Unexecuted instantiation: deflate_huff.c:bi_reverse
Unexecuted instantiation: deflate_medium.c:bi_reverse
Unexecuted instantiation: deflate_quick.c:bi_reverse
Unexecuted instantiation: deflate_rle.c:bi_reverse
Unexecuted instantiation: deflate_slow.c:bi_reverse
Unexecuted instantiation: deflate_stored.c:bi_reverse
trees.c:bi_reverse
Line
Count
Source
145
19.2M
Z_FORCEINLINE static uint16_t bi_reverse(uint16_t code, int len) {
146
    /* code: the value to invert */
147
    /* len: its bit length */
148
19.2M
    Assert(len >= 1 && len <= 15, "code length must be 1-15");
149
19.2M
    return zng_bitreverse16(code) >> (16 - len);
150
19.2M
}
151
152
/* ===========================================================================
153
 * Read a new buffer from the current input stream, update the adler32 and total number of
154
 * bytes read.  All deflate() input goes through this function so some applications may wish
155
 * to modify it to avoid allocating a large strm->next_in buffer and copying from it.
156
 * See also flush_pending_inline().
157
 */
158
147M
Z_FORCEINLINE static unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) {
159
147M
    deflate_state *s = strm->state;
160
147M
    uint32_t len = MIN(strm->avail_in, size);
161
162
147M
    if (len == 0)
163
0
        return 0;
164
165
147M
    if (!DEFLATE_NEED_CHECKSUM(strm)) {
166
0
        memcpy(buf, strm->next_in, len);
167
0
#ifdef GZIP
168
147M
    } else if (s->wrap == 2) {
169
22.3k
        strm->adler = FUNCTABLE_CALL(crc32_copy)(strm->adler, buf, strm->next_in, len);
170
22.3k
#endif
171
147M
    } else if (s->wrap == 1) {
172
147M
        strm->adler = FUNCTABLE_CALL(adler32_copy)(strm->adler, buf, strm->next_in, len);
173
147M
    } else {
174
10.6k
        memcpy(buf, strm->next_in, len);
175
10.6k
    }
176
177
147M
    strm->avail_in -= len;
178
147M
    strm->next_in  += len;
179
147M
    strm->total_in += len;
180
147M
    return len;
181
147M
}
deflate.c:read_buf
Line
Count
Source
158
147M
Z_FORCEINLINE static unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) {
159
147M
    deflate_state *s = strm->state;
160
147M
    uint32_t len = MIN(strm->avail_in, size);
161
162
147M
    if (len == 0)
163
0
        return 0;
164
165
147M
    if (!DEFLATE_NEED_CHECKSUM(strm)) {
166
0
        memcpy(buf, strm->next_in, len);
167
0
#ifdef GZIP
168
147M
    } else if (s->wrap == 2) {
169
21.2k
        strm->adler = FUNCTABLE_CALL(crc32_copy)(strm->adler, buf, strm->next_in, len);
170
21.2k
#endif
171
147M
    } else if (s->wrap == 1) {
172
147M
        strm->adler = FUNCTABLE_CALL(adler32_copy)(strm->adler, buf, strm->next_in, len);
173
147M
    } else {
174
10.6k
        memcpy(buf, strm->next_in, len);
175
10.6k
    }
176
177
147M
    strm->avail_in -= len;
178
147M
    strm->next_in  += len;
179
147M
    strm->total_in += len;
180
147M
    return len;
181
147M
}
Unexecuted instantiation: deflate_fast.c:read_buf
Unexecuted instantiation: deflate_huff.c:read_buf
Unexecuted instantiation: deflate_medium.c:read_buf
Unexecuted instantiation: deflate_quick.c:read_buf
Unexecuted instantiation: deflate_rle.c:read_buf
Unexecuted instantiation: deflate_slow.c:read_buf
deflate_stored.c:read_buf
Line
Count
Source
158
2.59k
Z_FORCEINLINE static unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) {
159
2.59k
    deflate_state *s = strm->state;
160
2.59k
    uint32_t len = MIN(strm->avail_in, size);
161
162
2.59k
    if (len == 0)
163
0
        return 0;
164
165
2.59k
    if (!DEFLATE_NEED_CHECKSUM(strm)) {
166
0
        memcpy(buf, strm->next_in, len);
167
0
#ifdef GZIP
168
2.59k
    } else if (s->wrap == 2) {
169
1.01k
        strm->adler = FUNCTABLE_CALL(crc32_copy)(strm->adler, buf, strm->next_in, len);
170
1.01k
#endif
171
1.58k
    } else if (s->wrap == 1) {
172
1.58k
        strm->adler = FUNCTABLE_CALL(adler32_copy)(strm->adler, buf, strm->next_in, len);
173
1.58k
    } else {
174
0
        memcpy(buf, strm->next_in, len);
175
0
    }
176
177
2.59k
    strm->avail_in -= len;
178
2.59k
    strm->next_in  += len;
179
2.59k
    strm->total_in += len;
180
2.59k
    return len;
181
2.59k
}
Unexecuted instantiation: trees.c:read_buf
182
183
/* ===========================================================================
184
 * Flush the current block, with given end-of-file flag.
185
 * IN assertion: strstart is set to the end of the current match.
186
 */
187
144k
#define FLUSH_BLOCK_ONLY(s, window, last) { \
188
144k
    int block_start = s->block_start; \
189
144k
    zng_tr_flush_block(s, (block_start >= 0 ? \
190
144k
                   &window[(unsigned)block_start] : \
191
144k
                   NULL), \
192
144k
                   (uint32_t)((int)s->strstart - block_start), \
193
144k
                   (last)); \
194
144k
    s->block_start = (int)s->strstart; \
195
144k
    PREFIX(flush_pending)(s->strm); \
196
144k
}
197
198
/* Same but force premature exit if necessary. */
199
130k
#define FLUSH_BLOCK(s, window, last) { \
200
130k
    FLUSH_BLOCK_ONLY(s, window, last); \
201
130k
    if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
202
130k
}
203
204
/* Maximum stored block length in deflate format (not including header). */
205
5.75k
#define MAX_STORED 65535
206
207
/* Compression function. Returns the block state after the call. */
208
typedef block_state (*compress_func) (deflate_state *s, int flush);
209
/* Match function. Returns the longest match. */
210
typedef uint32_t    (*match_func)    (deflate_state *const s, uint32_t cur_match);
211
212
#endif