|
| 1 | +From edabaf799fd071a328e0adb743a98628df6649f0 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Levi Broderick < [email protected]> |
| 3 | +Date: Mon, 28 Aug 2023 15:26:38 -0700 |
| 4 | +Subject: [PATCH] Make zlib-intel compile clean against C4244 clang equivalent |
| 5 | + is "implicit-int-conversion" warning |
| 6 | + |
| 7 | +The change to deflate.c is legal because 'len' has an upper bound of |
| 8 | +MAX_STORED, which means it fits cleanly into a 16-bit integer. So |
| 9 | +writing out 2x 8-bit values will not result in data loss. |
| 10 | + |
| 11 | +The change to trees.c is legal because within this loop, 'count' is |
| 12 | +intended to have an upper bound of 138, with the target assignment |
| 13 | +only executing if 'count' is bounded by 4. Neither the 'count' local |
| 14 | +in isolation nor the addition that's part of the target line is |
| 15 | +expected to result in integer overflow. But even if it did, that's a |
| 16 | +matter for a different warning code and doesn't impact the correctness |
| 17 | +of the narrowing cast being considered here. |
| 18 | + |
| 19 | +The change to slide_sse.c is legal because 'w_size' is limited to |
| 20 | +1 << 15 (see deflateInit2_ in deflate.c), so this fits cleanly into |
| 21 | +a 16-bit value. |
| 22 | +--- |
| 23 | + src/native/external/zlib-intel/deflate.c | 8 ++++---- |
| 24 | + src/native/external/zlib-intel/slide_sse.c | 2 +- |
| 25 | + src/native/external/zlib-intel/trees.c | 2 +- |
| 26 | + 3 files changed, 6 insertions(+), 6 deletions(-) |
| 27 | + |
| 28 | +diff --git a/src/native/external/zlib-intel/deflate.c b/src/native/external/zlib-intel/deflate.c |
| 29 | +index bd5e95774a6..108b1a187af 100644 |
| 30 | +--- a/src/native/external/zlib-intel/deflate.c |
| 31 | ++++ b/src/native/external/zlib-intel/deflate.c |
| 32 | +@@ -1553,10 +1553,10 @@ local block_state deflate_stored(s, flush) |
| 33 | + _tr_stored_block(s, (char *)0, 0L, last); |
| 34 | + |
| 35 | + /* Replace the lengths in the dummy stored block with len. */ |
| 36 | +- s->pending_buf[s->pending - 4] = len; |
| 37 | +- s->pending_buf[s->pending - 3] = len >> 8; |
| 38 | +- s->pending_buf[s->pending - 2] = ~len; |
| 39 | +- s->pending_buf[s->pending - 1] = ~len >> 8; |
| 40 | ++ s->pending_buf[s->pending - 4] = (Bytef)len; |
| 41 | ++ s->pending_buf[s->pending - 3] = (Bytef)(len >> 8); |
| 42 | ++ s->pending_buf[s->pending - 2] = (Bytef)~len; |
| 43 | ++ s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8); |
| 44 | + |
| 45 | + /* Write the stored block header bytes. */ |
| 46 | + flush_pending(s->strm); |
| 47 | +diff --git a/src/native/external/zlib-intel/slide_sse.c b/src/native/external/zlib-intel/slide_sse.c |
| 48 | +index 342fd562dd1..eb74202c5a0 100644 |
| 49 | +--- a/src/native/external/zlib-intel/slide_sse.c |
| 50 | ++++ b/src/native/external/zlib-intel/slide_sse.c |
| 51 | +@@ -18,7 +18,7 @@ void slide_hash_sse(deflate_state *s) |
| 52 | + unsigned n; |
| 53 | + Posf *p; |
| 54 | + uInt wsize = s->w_size; |
| 55 | +- z_const __m128i xmm_wsize = _mm_set1_epi16(s->w_size); |
| 56 | ++ z_const __m128i xmm_wsize = _mm_set1_epi16((short)s->w_size); |
| 57 | + |
| 58 | + n = s->hash_size; |
| 59 | + p = &s->head[n] - 8; |
| 60 | +diff --git a/src/native/external/zlib-intel/trees.c b/src/native/external/zlib-intel/trees.c |
| 61 | +index 35462a1313a..f78b7d8c63e 100644 |
| 62 | +--- a/src/native/external/zlib-intel/trees.c |
| 63 | ++++ b/src/native/external/zlib-intel/trees.c |
| 64 | +@@ -717,7 +717,7 @@ local void scan_tree(s, tree, max_code) |
| 65 | + if (++count < max_count && curlen == nextlen) { |
| 66 | + continue; |
| 67 | + } else if (count < min_count) { |
| 68 | +- s->bl_tree[curlen].Freq += count; |
| 69 | ++ s->bl_tree[curlen].Freq += (ush)count; |
| 70 | + } else if (curlen != 0) { |
| 71 | + if (curlen != prevlen) s->bl_tree[curlen].Freq++; |
| 72 | + s->bl_tree[REP_3_6].Freq++; |
| 73 | +-- |
| 74 | +2.42.0.windows.1 |
| 75 | + |
0 commit comments