* Initialize the tree data structures for a new zlib stream.
*/
void Z_INTERNAL zng_tr_init(deflate_state *s) {
+ Assume(s != NULL);
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
* Initialize a new block.
*/
static void init_block(deflate_state *s) {
+ Assume(s != NULL);
int n; /* iterates over tree elements */
/* Initialize the trees. */
static void pqdownheap(deflate_state *s, ct_data *tree, int k) {
/* tree: the tree to restore */
/* k: node to move down */
+ Assume(s != NULL && tree != NULL);
int v = s->heap[k];
int j = k << 1; /* left son of k */
while (j <= s->heap_len) {
*/
static void gen_bitlen(deflate_state *s, tree_desc *desc) {
/* desc: the tree descriptor */
+ Assume(s != NULL && desc != NULL);
ct_data *tree = desc->dyn_tree;
int max_code = desc->max_code;
const ct_data *stree = desc->stat_desc->static_tree;
*/
static void build_tree(deflate_state *s, tree_desc *desc) {
/* desc: the tree descriptor */
+ Assume(s != NULL && desc != NULL);
ct_data *tree = desc->dyn_tree;
const ct_data *stree = desc->stat_desc->static_tree;
int elems = desc->stat_desc->elems;
static void scan_tree(deflate_state *s, ct_data *tree, int max_code) {
/* tree: the tree to be scanned */
/* max_code: and its largest code of non zero frequency */
+ Assume(s != NULL && tree != NULL);
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */
static void send_tree(deflate_state *s, ct_data *tree, int max_code) {
/* tree: the tree to be scanned */
/* max_code and its largest code of non zero frequency */
+ Assume(s != NULL && tree != NULL);
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
int curlen; /* length of current code */
* bl_order of the last bit length code to send.
*/
static int build_bl_tree(deflate_state *s) {
+ Assume(s != NULL);
int max_blindex; /* index of last bit length code of non zero freq */
/* Determine the bit length frequencies for literal and distance trees */
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/
static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes) {
+ Assume(s != NULL);
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
int rank; /* index in bl_order */
AssertHint(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
/* buf: input block */
/* stored_len: length of input block */
/* last: one if this is the last block for a file */
+ Assume(s != NULL);
+
zng_tr_emit_tree(s, STORED_BLOCK, last); /* send block type */
zng_tr_emit_align(s); /* align on byte boundary */
cmpr_bits_align(s);
* This takes 10 bits, of which 7 may remain in the bit buffer.
*/
void Z_INTERNAL zng_tr_align(deflate_state *s) {
+ Assume(s != NULL);
zng_tr_emit_tree(s, STATIC_TREES, 0);
zng_tr_emit_end_block(s, static_ltree, 0);
zng_tr_flush_bits(s);
/* buf: input block, or NULL if too old */
/* stored_len: length of input block */
/* last: one if this is the last block for a file */
+ Assume(s != NULL);
+
unsigned long opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex = 0; /* index of last bit length code of non zero freq */
opt_lenb = static_lenb;
} else {
- Assert(buf != NULL, "lost buf");
+ AssertHint(buf != NULL, "lost buf");
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
}
static void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree) {
/* ltree: literal tree */
/* dtree: distance tree */
+ Assume(s != NULL && ltree != NULL && dtree != NULL);
+
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
unsigned sx = 0; /* running index in symbol buffers */
* IN assertion: the fields Freq of dyn_ltree are set.
*/
static int detect_data_type(deflate_state *s) {
+ Assume(s != NULL);
/* black_mask is the bit mask of black-listed bytes
* set bits 0..6, 14..25, and 28..31
* 0xf3ffc07f = binary 11110011111111111100000001111111
* Flush the bit buffer, keeping at most 7 bits in it.
*/
void Z_INTERNAL zng_tr_flush_bits(deflate_state *s) {
+ Assume(s != NULL);
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
if (s->bi_valid >= 48) {
put_uint32(s, (uint32_t)s->bi_buf);
put_short(s, (uint16_t)(s->bi_buf >> 32));
* otherwise the shifts will overflow.
*/
#define send_bits(s, t_val, t_len, bi_buf, bi_valid) {\
+ Assume(bi_valid <= BIT_BUF_SIZE);\
uint64_t val = (uint64_t)t_val;\
uint32_t len = (uint32_t)t_len;\
uint32_t total_bits = bi_valid + len;\
* Flush the bit buffer and align the output on a byte boundary
*/
static void bi_windup(deflate_state *s) {
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
+
if (s->bi_valid > 56) {
put_uint64(s, s->bi_buf);
} else {
* Emit literal code
*/
static inline uint32_t zng_emit_lit(deflate_state *s, const ct_data *ltree, unsigned c) {
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
uint32_t bi_valid = s->bi_valid;
uint64_t bi_buf = s->bi_buf;
*/
static inline uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, const ct_data *dtree,
uint32_t lc, uint32_t dist) {
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
uint32_t c, extra;
uint8_t code;
uint64_t match_bits;
* Emit end block
*/
static inline void zng_emit_end_block(deflate_state *s, const ct_data *ltree, const int last) {
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
uint32_t bi_valid = s->bi_valid;
uint64_t bi_buf = s->bi_buf;
send_code(s, END_BLOCK, ltree, bi_buf, bi_valid);
* Emit start of block
*/
static inline void zng_tr_emit_tree(deflate_state *s, int type, const int last) {
+ Assume(s->bi_valid <= BIT_BUF_SIZE);
uint32_t bi_valid = s->bi_valid;
uint64_t bi_buf = s->bi_buf;
uint32_t header_bits = (type << 1) + last;