|
| 1 | +From 86d96652ddd60f61dc7b0c94b601f6d156d34632 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 compile clean against C4244 clang equivalent is |
| 5 | + "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 | + src/native/external/zlib/deflate.c | 8 ++++---- |
| 20 | + src/native/external/zlib/trees.c | 2 +- |
| 21 | + 2 files changed, 5 insertions(+), 5 deletions(-) |
| 22 | + |
| 23 | +diff --git a/src/native/external/zlib/deflate.c b/src/native/external/zlib/deflate.c |
| 24 | +index d2e1106ef5d..b7636639754 100644 |
| 25 | +--- a/src/native/external/zlib/deflate.c |
| 26 | ++++ b/src/native/external/zlib/deflate.c |
| 27 | +@@ -1738,10 +1738,10 @@ local block_state deflate_stored(s, flush) |
| 28 | + _tr_stored_block(s, (char *)0, 0L, last); |
| 29 | + |
| 30 | + /* Replace the lengths in the dummy stored block with len. */ |
| 31 | +- s->pending_buf[s->pending - 4] = len; |
| 32 | +- s->pending_buf[s->pending - 3] = len >> 8; |
| 33 | +- s->pending_buf[s->pending - 2] = ~len; |
| 34 | +- s->pending_buf[s->pending - 1] = ~len >> 8; |
| 35 | ++ s->pending_buf[s->pending - 4] = (Bytef)len; |
| 36 | ++ s->pending_buf[s->pending - 3] = (Bytef)(len >> 8); |
| 37 | ++ s->pending_buf[s->pending - 2] = (Bytef)~len; |
| 38 | ++ s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8); |
| 39 | + |
| 40 | + /* Write the stored block header bytes. */ |
| 41 | + flush_pending(s->strm); |
| 42 | +diff --git a/src/native/external/zlib/trees.c b/src/native/external/zlib/trees.c |
| 43 | +index 5f305c47221..8a3eec559e5 100644 |
| 44 | +--- a/src/native/external/zlib/trees.c |
| 45 | ++++ b/src/native/external/zlib/trees.c |
| 46 | +@@ -721,7 +721,7 @@ local void scan_tree(s, tree, max_code) |
| 47 | + if (++count < max_count && curlen == nextlen) { |
| 48 | + continue; |
| 49 | + } else if (count < min_count) { |
| 50 | +- s->bl_tree[curlen].Freq += count; |
| 51 | ++ s->bl_tree[curlen].Freq += (ush)count; |
| 52 | + } else if (curlen != 0) { |
| 53 | + if (curlen != prevlen) s->bl_tree[curlen].Freq++; |
| 54 | + s->bl_tree[REP_3_6].Freq++; |
| 55 | +-- |
| 56 | +2.42.0.windows.1 |
| 57 | + |
0 commit comments