static void lm_init (deflate_state *s);
static void putShortMSB (deflate_state *s, uint16_t b);
ZLIB_INTERNAL void flush_pending (z_stream *strm);
-ZLIB_INTERNAL int read_buf (z_stream *strm, unsigned char *buf, unsigned size);
+ZLIB_INTERNAL unsigned read_buf (z_stream *strm, unsigned char *buf, unsigned size);
extern void crc_reset(deflate_state *const s);
extern void crc_finalize(deflate_state *const s);
s->wrap = wrap;
s->gzhead = NULL;
- s->w_bits = windowBits;
+ s->w_bits = (unsigned int)windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
#ifdef X86_SSE4_2_CRC_HASH
if (x86_cpu_has_sse42)
- s->hash_bits = 15;
+ s->hash_bits = (unsigned int)15;
else
#endif
- s->hash_bits = memLevel + 7;
+ s->hash_bits = (unsigned int)memLevel + 7;
s->hash_size = 1 << s->hash_bits;
s->hash_mask = s->hash_size - 1;
if (strm == NULL || strm->state == NULL)
return Z_STREAM_ERROR;
s = strm->state;
- s->good_match = good_length;
- s->max_lazy_match = max_lazy;
+ s->good_match = (unsigned int)good_length;
+ s->max_lazy_match = (unsigned int)max_lazy;
s->nice_match = nice_length;
- s->max_chain_length = max_chain;
+ s->max_chain_length = (unsigned int)max_chain;
return Z_OK;
}
* allocating a large strm->next_in buffer and copying from it.
* (See also flush_pending()).
*/
-ZLIB_INTERNAL int read_buf(z_stream *strm, unsigned char *buf, unsigned size) {
+ZLIB_INTERNAL unsigned read_buf(z_stream *strm, unsigned char *buf, unsigned size) {
uint32_t len = strm->avail_in;
if (len > size)
strm->next_in += len;
strm->total_in += len;
- return (int)len;
+ return len;
}
/* ===========================================================================
s->lookahead = 0;
/* Emit a stored block if pending_buf will be full: */
- max_start = s->block_start + max_block_size;
+ max_start = max_block_size + (unsigned long)s->block_start;
if (s->strstart == 0 || (unsigned long)s->strstart >= max_start) {
/* strstart == 0 is possible when wraparound on 16-bit machine */
s->lookahead = (unsigned int)(s->strstart - max_start);
prev == *++scan && prev == *++scan &&
prev == *++scan && prev == *++scan &&
scan < strend);
- s->match_length = MAX_MATCH - (int)(strend - scan);
+ s->match_length = MAX_MATCH - (unsigned int)(strend - scan);
if (s->match_length > s->lookahead)
s->match_length = s->lookahead;
}
/* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf.
*/
-#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
+#define put_byte(s, c) {s->pending_buf[s->pending++] = (unsigned char)(c);}
/* ===========================================================================
* Output a short LSB first on the stream.
flush = (s->last_lit == s->lit_bufsize-1); \
}
# define _tr_tally_dist(s, distance, length, flush) \
- { unsigned char len = (length); \
- uint16_t dist = (distance); \
+ { unsigned char len = (unsigned char)(length); \
+ uint16_t dist = (uint16_t)(distance); \
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \
dist--; \
#define send_bits(s, value, length) \
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
- int val = value;\
+ int val = (int)value;\
s->bi_buf |= (uint16_t)val << s->bi_valid;\
put_short(s, s->bi_buf);\
s->bi_buf = (uint16_t)val >> (Buf_size - s->bi_valid);\
This function needs to loop on read(), since read() is not guaranteed to
read the number of bytes requested, depending on the type of descriptor. */
static int gz_load(gz_statep state, unsigned char *buf, unsigned len, unsigned *have) {
- int ret;
+ ssize_t ret;
*have = 0;
do {
ret = read(state->fd, buf + *have, len - *have);
if (ret <= 0)
break;
- *have += ret;
+ *have += (unsigned)ret;
} while (*have < len);
if (ret < 0) {
gz_error(state, Z_ERRNO, zstrerror());
if (state->x.have == 0) {
state->x.have = 1;
state->x.next = state->out + (state->size << 1) - 1;
- state->x.next[0] = c;
+ state->x.next[0] = (unsigned char)c;
state->x.pos--;
state->past = 0;
return c;
}
state->x.have++;
state->x.next--;
- state->x.next[0] = c;
+ state->x.next[0] = (unsigned char)c;
state->x.pos--;
state->past = 0;
return c;
is true, then simply write to the output file without compressing, and
ignore flush. */
static int gz_comp(gz_statep state, int flush) {
- int ret, got;
+ int ret;
+ ssize_t got;
unsigned have;
z_stream *strm = &(state->strm);
doing Z_FINISH then don't write until we get to Z_STREAM_END */
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && (flush != Z_FINISH || ret == Z_STREAM_END))) {
have = (unsigned)(strm->next_out - state->x.next);
- if (have && ((got = write(state->fd, state->x.next, have)) < 0 || (unsigned)got != have)) {
+ if (have && ((got = write(state->fd, state->x.next, (unsigned long)have)) < 0 || (unsigned)got != have)) {
gz_error(state, Z_ERRNO, zstrerror());
return -1;
}
strm->next_in = state->in;
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
if (have < state->size) {
- state->in[have] = c;
+ state->in[have] = (unsigned char)c;
strm->avail_in++;
state->x.pos++;
return c & 0xff;
}
/* no room in buffer or not initialized, use gz_write() */
- buf[0] = c;
+ buf[0] = (unsigned char)c;
if (gzwrite(file, buf, 1) != 1)
return -1;
return c & 0xff;
/* -- see zlib.h -- */
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
- int len, left;
+ int len;
+ unsigned left;
char *next;
gz_statep state;
z_stream *strm;
be state->size bytes available after the current contents */
if (strm->avail_in == 0)
strm->next_in = state->in;
- next = (char *)(strm->next_in + strm->avail_in);
+ next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
next[state->size - 1] = 0;
len = vsnprintf(next, state->size, format, va);
/* check that printf() results fit in buffer */
- if (len == 0 || len >= state->size || next[state->size - 1] != 0)
+ if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
return 0;
/* update buffer and position, compress first half if past that */
- strm->avail_in += len;
+ strm->avail_in += (unsigned)len;
state->x.pos += len;
if (strm->avail_in >= state->size) {
left = strm->avail_in - state->size;
strm->next_in = state->in;
strm->avail_in = left;
}
- return (int)len;
+ return len;
}
int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) {
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state *)state;
state->dmax = 32768U;
- state->wbits = windowBits;
+ state->wbits = (uInt)windowBits;
state->wsize = 1U << windowBits;
state->window = window;
state->wnext = 0;
state->bits = 0;
return Z_OK;
}
- if (bits > 16 || state->bits + bits > 32)
+ if (bits > 16 || state->bits + (unsigned int)bits > 32)
return Z_STREAM_ERROR;
value &= (1L << bits) - 1;
state->hold += (unsigned)value << state->bits;
- state->bits += bits;
+ state->bits += (unsigned int)bits;
return Z_OK;
}
do {
len = (unsigned)(next[copy++]);
if (state->head != NULL && state->head->name != NULL && state->length < state->head->name_max)
- state->head->name[state->length++] = len;
+ state->head->name[state->length++] = (unsigned char)len;
} while (len && copy < have);
if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
len = (unsigned)(next[copy++]);
if (state->head != NULL && state->head->comment != NULL
&& state->length < state->head->comm_max)
- state->head->comment[state->length++] = len;
+ state->head->comment[state->length++] = (unsigned char)len;
} while (len && copy < have);
if ((state->flags & 0x0200) && (state->wrap & 4))
state->check = crc32(state->check, next, copy);
state->total += out;
if ((state->wrap & 4) && out)
strm->adler = state->check = UPDATE(state->check, strm->next_out - out, out);
- strm->data_type = state->bits + (state->last ? 64 : 0) +
+ strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
(state->mode == TYPE ? 128 : 0) + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
ret = Z_BUF_ERROR;
state->sane = !subvert;
return Z_OK;
#else
+ (void)subvert;
state->sane = 1;
return Z_DATA_ERROR;
#endif
if (n >= base)
xbits = extra[n-base];
f = tree[n].Freq;
- s->opt_len += (unsigned long)f * (bits + xbits);
+ s->opt_len += (unsigned long)f * (unsigned int)(bits + xbits);
if (stree)
- s->static_len += (unsigned long)f * (stree[n].Len + xbits);
+ s->static_len += (unsigned long)f * (unsigned int)(stree[n].Len + xbits);
}
if (overflow == 0)
return;
continue;
if (tree[m].Len != bits) {
Trace((stderr, "code %d bits %d->%u\n", m, tree[m].Len, bits));
- s->opt_len += (long)((bits - tree[m].Len) * tree[m].Freq);
+ s->opt_len += (unsigned long)((bits - tree[m].Len) * tree[m].Freq);
tree[m].Len = (uint16_t)bits;
}
n--;
/* max_code: largest code with non zero frequency */
/* bl_count: number of codes at each bit length */
uint16_t next_code[MAX_BITS+1]; /* next code value for each bit length */
- uint16_t code = 0; /* running code value */
+ unsigned int code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
* without bit reversal.
*/
for (bits = 1; bits <= MAX_BITS; bits++) {
- next_code[bits] = code = (code + bl_count[bits-1]) << 1;
+ code = (code + bl_count[bits-1]) << 1;
+ next_code[bits] = (uint16_t)code;
}
/* Check that the bit counts in bl_count are consistent. The last code
* must be all ones.
if (len == 0)
continue;
/* Now reverse the bits */
- tree[n].Code = bi_reverse(next_code[len]++, len);
+ tree[n].Code = (uint16_t)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr, "\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
break;
}
/* Update opt_len to include the bit length tree and counts */
- s->opt_len += 3*(max_blindex+1) + 5+5+4;
+ s->opt_len += 3*((unsigned long)max_blindex+1) + 5+5+4;
Tracev((stderr, "\ndyn trees: dyn %lu, stat %lu", s->opt_len, s->static_len));
return max_blindex;
send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code];
if (extra != 0) {
- dist -= base_dist[code];
+ dist -= (unsigned int)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */
}
} /* literal or match pair ? */
#endif
const char * const z_errmsg[10] = {
-"need dictionary", /* Z_NEED_DICT 2 */
-"stream end", /* Z_STREAM_END 1 */
-"", /* Z_OK 0 */
-"file error", /* Z_ERRNO (-1) */
-"stream error", /* Z_STREAM_ERROR (-2) */
-"data error", /* Z_DATA_ERROR (-3) */
-"insufficient memory", /* Z_MEM_ERROR (-4) */
-"buffer error", /* Z_BUF_ERROR (-5) */
-"incompatible version",/* Z_VERSION_ERROR (-6) */
-""};
+ (const char *)"need dictionary", /* Z_NEED_DICT 2 */
+ (const char *)"stream end", /* Z_STREAM_END 1 */
+ (const char *)"", /* Z_OK 0 */
+ (const char *)"file error", /* Z_ERRNO (-1) */
+ (const char *)"stream error", /* Z_STREAM_ERROR (-2) */
+ (const char *)"data error", /* Z_DATA_ERROR (-3) */
+ (const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
+ (const char *)"buffer error", /* Z_BUF_ERROR (-5) */
+ (const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
+ (const char *)""
+};
const char zlibng_string[] =
" zlib-ng 1.9.9 forked from zlib 1.2.8 ";