Skip to content

Commit

Permalink
Fixes build issues C4242, C4244 and C4334 caused by loss of data bug…
Browse files Browse the repository at this point in the history
…s due to data type mismatch in various files.
  • Loading branch information
carlossanlop authored and Dead2 committed Aug 16, 2024
1 parent f858914 commit 3da40c2
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion arch/arm/slide_hash_armv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
}

Z_INTERNAL void slide_hash_armv6(deflate_state *s) {
unsigned int wsize = s->w_size;
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
uint16_t wsize = (uint16_t)s->w_size;

slide_hash_chain(s->head, HASH_SIZE, wsize);
slide_hash_chain(s->prev, wsize, wsize);
Expand Down
3 changes: 2 additions & 1 deletion arch/arm/slide_hash_neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
}

Z_INTERNAL void slide_hash_neon(deflate_state *s) {
unsigned int wsize = s->w_size;
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
uint16_t wsize = (uint16_t)s->w_size;

slide_hash_chain(s->head, HASH_SIZE, wsize);
slide_hash_chain(s->prev, wsize, wsize);
Expand Down
1 change: 1 addition & 0 deletions arch/generic/crc32_braid_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Z_INTERNAL uint32_t PREFIX(crc32_braid)(uint32_t crc, const uint8_t *buf, size_t
#endif
#endif
words += N;
Assert(comb <= UINT32_MAX, "comb should fit in uint32_t");
c = (uint32_t)ZSWAPWORD(comb);

/* Update the pointer to the remaining bytes to process. */
Expand Down
3 changes: 2 additions & 1 deletion arch/power/slide_ppc_tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
}

void Z_INTERNAL SLIDE_PPC(deflate_state *s) {
uint16_t wsize = s->w_size;
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
uint16_t wsize = (uint16_t)s->w_size;

slide_hash_chain(s->head, HASH_SIZE, wsize);
slide_hash_chain(s->prev, wsize, wsize);
Expand Down
1 change: 1 addition & 0 deletions arch/riscv/slide_hash_rvv.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
}

Z_INTERNAL void slide_hash_rvv(deflate_state *s) {
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
uint16_t wsize = (uint16_t)s->w_size;

slide_hash_chain(s->head, HASH_SIZE, wsize);
Expand Down
1 change: 1 addition & 0 deletions arch/x86/slide_hash_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m256i
}

Z_INTERNAL void slide_hash_avx2(deflate_state *s) {
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
uint16_t wsize = (uint16_t)s->w_size;
const __m256i ymm_wsize = _mm256_set1_epi16((short)wsize);

Expand Down
1 change: 1 addition & 0 deletions arch/x86/slide_hash_sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static inline void slide_hash_chain(Pos *table0, Pos *table1, uint32_t entries0,
}

Z_INTERNAL void slide_hash_sse2(deflate_state *s) {
Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
uint16_t wsize = (uint16_t)s->w_size;
const __m128i xmm_wsize = _mm_set1_epi16((short)wsize);

Expand Down
2 changes: 1 addition & 1 deletion deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Z_INTERNAL deflate_allocs* alloc_deflate(PREFIX3(stream) *strm, int windowBits,

/* Define sizes */
int window_size = DEFLATE_ADJUST_WINDOW_SIZE((1 << windowBits) * 2);
int prev_size = (1 << windowBits) * sizeof(Pos);
int prev_size = (1 << windowBits) * (int)sizeof(Pos);
int head_size = HASH_SIZE * sizeof(Pos);
int pending_size = lit_bufsize * LIT_BUFS;
int state_size = sizeof(deflate_state);
Expand Down
4 changes: 3 additions & 1 deletion deflate_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
}

if (match_len >= WANT_MIN_MATCH) {
check_match(s, s->strstart, s->match_start, match_len);
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t");
check_match(s, (Pos)s->strstart, (Pos)s->match_start, match_len);

bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH);

Expand Down
6 changes: 4 additions & 2 deletions deflate_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t le
/* dist: distance of matched string */
/* len: match length-STD_MIN_MATCH */
#ifdef LIT_MEM
s->d_buf[s->sym_next] = dist;
s->l_buf[s->sym_next++] = len;
Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
Assert(len <= UINT8_MAX, "len should fit in uint8_t");
s->d_buf[s->sym_next] = (uint16_t)dist;
s->l_buf[s->sym_next++] = (uint8_t)len;
#else
s->sym_buf[s->sym_next++] = (uint8_t)(dist);
s->sym_buf[s->sym_next++] = (uint8_t)(dist >> 8);
Expand Down
3 changes: 2 additions & 1 deletion deflate_quick.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
if (UNLIKELY(match_len > STD_MAX_MATCH))
match_len = STD_MAX_MATCH;

check_match(s, s->strstart, hash_head, match_len);
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
check_match(s, (Pos)s->strstart, hash_head, match_len);

zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist);
s->lookahead -= match_len;
Expand Down
3 changes: 2 additions & 1 deletion deflate_rle.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) {

/* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */
if (match_len >= STD_MIN_MATCH) {
check_match(s, s->strstart, s->strstart - 1, match_len);
Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
check_match(s, (Pos)s->strstart, (Pos)(s->strstart - 1), match_len);

bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH);

Expand Down
3 changes: 2 additions & 1 deletion deflate_slow.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
unsigned int max_insert = s->strstart + s->lookahead - STD_MIN_MATCH;
/* Do not insert strings in hash table beyond this. */

check_match(s, s->strstart-1, s->prev_match, s->prev_length);
Assert((s->strstart-1) <= UINT16_MAX, "strstart-1 should fit in uint16_t");
check_match(s, (Pos)(s->strstart - 1), s->prev_match, s->prev_length);

bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH);

Expand Down

0 comments on commit 3da40c2

Please sign in to comment.