do { \
PULL(); \
have--; \
- hold += ((unsigned)(*next++) << bits); \
+ hold += ((uint64_t)(*next++) << bits); \
bits += 8; \
} while (0)
z_const unsigned char *next; /* next input */
unsigned char *put; /* next output */
unsigned have, left; /* available input and output */
- uint32_t hold; /* bit buffer */
+ uint64_t hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned copy; /* number of stored or match bytes to copy */
unsigned char *from; /* where to copy match bytes from */
if (bits > 16 || state->bits + (unsigned int)bits > 32)
return Z_STREAM_ERROR;
value &= (1L << bits) - 1;
- state->hold += (unsigned)value << state->bits;
+ state->hold += (uint64_t)value << state->bits;
state->bits += (unsigned int)bits;
return Z_OK;
}
do { \
if (have == 0) goto inf_leave; \
have--; \
- hold += ((unsigned)(*next++) << bits); \
+ hold += ((uint64_t)(*next++) << bits); \
bits += 8; \
} while (0)
unsigned char *put; /* next output */
unsigned char *from; /* where to copy match bytes from */
unsigned have, left; /* available input and output */
- uint32_t hold; /* bit buffer */
+ uint64_t hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
uint32_t in, out; /* save starting available input and output */
unsigned copy; /* number of stored or match bytes to copy */
case TIME:
NEEDBITS(32);
if (state->head != NULL)
- state->head->time = hold;
+ state->head->time = (unsigned)(hold);
if ((state->flags & 0x0200) && (state->wrap & 4))
CRC4(state->check, hold);
INITBITS();
#endif
case DICTID:
NEEDBITS(32);
- strm->adler = state->check = ZSWAP32(hold);
+ strm->adler = state->check = ZSWAP32((unsigned)hold);
INITBITS();
state->mode = DICT;
Z_FALLTHROUGH;
#ifdef GUNZIP
state->flags ? hold :
#endif
- ZSWAP32(hold)) != state->check) {
+ ZSWAP32((unsigned)hold)) != state->check) {
SET_BAD("incorrect data check");
break;
}
uint32_t chunksize; /* size of memory copying chunk */
/* bit accumulator */
- uint32_t hold; /* input bit accumulator */
+ uint64_t hold; /* input bit accumulator */
unsigned bits; /* number of bits in "in" */
/* fixed and dynamic code tables */
unsigned lenbits; /* index bits for lencode */
code *next; /* next available space in codes[] */
#if defined(_M_IX86) || defined(_M_ARM)
- uint32_t padding[2];
+ uint32_t padding[1];
#endif
struct crc32_fold_s ALIGNED_(16) crc_fold;
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (64 - bi_valid) bits from value, leaving (width - (64-bi_valid))
* unused bits in value.
+ *
+ * NOTE: Static analyzers can't evaluate value of total_bits, so we
+ * also need to make sure bi_valid is within acceptable range,
+ * otherwise the shifts will overflow.
*/
#define send_bits(s, t_val, t_len, bi_buf, bi_valid) {\
uint64_t val = (uint64_t)t_val;\
uint32_t total_bits = bi_valid + len;\
send_bits_trace(s, val, len);\
sent_bits_add(s, len);\
- if (total_bits < BIT_BUF_SIZE) {\
+ if (total_bits < BIT_BUF_SIZE && bi_valid < BIT_BUF_SIZE) {\
bi_buf |= val << bi_valid;\
bi_valid = total_bits;\
- } else if (bi_valid == BIT_BUF_SIZE) {\
+ } else if (bi_valid >= BIT_BUF_SIZE) {\
put_uint64(s, bi_buf);\
bi_buf = val;\
bi_valid = len;\