]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Convert various Assert() calls to AssertHint() where these can provide
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 4 Nov 2024 21:16:39 +0000 (22:16 +0100)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 11 Feb 2025 22:21:34 +0000 (23:21 +0100)
useful hints to compiler and static analyzers.

20 files changed:
arch/arm/slide_hash_armv6.c
arch/arm/slide_hash_neon.c
arch/generic/crc32_braid_c.c
arch/power/slide_ppc_tpl.h
arch/riscv/chunkset_rvv.c
arch/riscv/slide_hash_rvv.c
arch/s390/dfltcc_deflate.c
arch/x86/slide_hash_avx2.c
arch/x86/slide_hash_sse2.c
chunkset_tpl.h
deflate.c
deflate_fast.c
deflate_p.h
deflate_quick.c
deflate_rle.c
deflate_slow.c
fallback_builtins.h
inffast_tpl.h
trees.c
trees_emit.h

index da4f51e0afc8240f4d372f8c3be6019b74753015..1bcdb84a0ade282b4c8e9a0d75921e37b0d78622 100644 (file)
@@ -39,7 +39,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
 }
 
 Z_INTERNAL void slide_hash_armv6(deflate_state *s) {
-    Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
+    AssertHint(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);
index f319f987908a224f60fc106cb0c4fce29a945d57..71f905ff56bb249ddfa190aa98d7b14ad4c820b9 100644 (file)
@@ -38,7 +38,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
 }
 
 Z_INTERNAL void slide_hash_neon(deflate_state *s) {
-    Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
+    AssertHint(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);
index f80071042d77c601e11aaf096beea66c846de606..ad60cc963e50e08574fc7c064de45b7da1aa20a9 100644 (file)
@@ -192,7 +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");
+        AssertHint(comb <= UINT32_MAX, "comb should fit in uint32_t");
         c = (uint32_t)ZSWAPWORD(comb);
 
         /* Update the pointer to the remaining bytes to process. */
index 680a7f8e2af4076f2b654fb865dca361514a7549..795efe9681ca10cffa4b3c5fb13a7dae594f7081 100644 (file)
@@ -24,7 +24,7 @@ static inline void slide_hash_chain(Pos *table, uint32_t entries, uint16_t wsize
 }
 
 void Z_INTERNAL SLIDE_PPC(deflate_state *s) {
-    Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
+    AssertHint(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);
index ee43bde2f71d81b3e6f9b2d03ae13a7dec7ff7b1..dbba222b1cd3adffb6a02b8e3aaccfc01dbf0685 100644 (file)
@@ -85,7 +85,7 @@ static inline void storechunk(uint8_t *out, chunk_t *chunk) {
  *         loadchunk and storechunk to ensure the result is correct.
  */
 static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len) {
-    Assert(len > 0, "chunkcopy should never have a length 0");
+    AssertHint(len > 0, "chunkcopy should never have a length 0");
     int32_t align = ((len - 1) % sizeof(chunk_t)) + 1;
     memcpy(out, from, sizeof(chunk_t));
     out += align;
index 6f53d7a13ad81b15cc36d347e241603382c7323e..91030cb9b030518fc410ff3958921109b12fb259 100644 (file)
@@ -23,7 +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");
+    AssertHint(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);
index 90b4b96e9ce33509e717eebd71749dc5b4b9128c..f45ebf6db5171e4a9324dfe943100d6734f75258 100644 (file)
@@ -215,8 +215,8 @@ again:
     /* DFLTCC-CMPR will write to next_out, so make sure that buffers with
      * higher precedence are empty.
      */
-    Assert(state->pending == 0, "There must be no pending bytes");
-    Assert(state->bi_valid < 8, "There must be less than 8 pending bits");
+    AssertHint(state->pending == 0, "There must be no pending bytes");
+    AssertHint(state->bi_valid < 8, "There must be less than 8 pending bits");
     param->sbb = (unsigned int)state->bi_valid;
     if (param->sbb > 0)
         *strm->next_out = (unsigned char)state->bi_buf;
index 853347323436eb43e14653a44fbee979e2ed8bb7..d188f18ab8b0b730a0672502bed36081a7cfec93 100644 (file)
@@ -31,7 +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");
+    AssertHint(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);
 
index 6900a59d15dfac7cb1879ed999b015cd050a20f1..3b39d08508f4756059705fb371398983e8998780 100644 (file)
@@ -52,7 +52,7 @@ next_chain:
 }
 
 Z_INTERNAL void slide_hash_sse2(deflate_state *s) {
-    Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t");
+    AssertHint(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);
 
index 383b4d8f84b1120c1affbe1738cca5a8ca95594b..9551f9d5c467130237e2b62126ab5747fbf4ea13 100644 (file)
@@ -22,7 +22,7 @@ Z_INTERNAL uint32_t CHUNKSIZE(void) {
    reliable. */
 #ifndef HAVE_CHUNKCOPY
 static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len) {
-    Assert(len > 0, "chunkcopy should never have a length 0");
+    AssertHint(len > 0, "chunkcopy should never have a length 0");
     chunk_t chunk;
     int32_t align = ((len - 1) % sizeof(chunk_t)) + 1;
     loadchunk(from, &chunk);
@@ -112,7 +112,7 @@ static inline uint8_t* HALFCHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned
 static inline uint8_t* CHUNKMEMSET(uint8_t *out, uint8_t *from, unsigned len) {
     /* Debug performance related issues when len < sizeof(uint64_t):
        Assert(len >= sizeof(uint64_t), "chunkmemset should be called on larger chunks"); */
-    Assert(from != out, "chunkmemset cannot have a distance 0");
+    AssertHint(from != out, "chunkmemset cannot have a distance 0");
 
     chunk_t chunk_load;
     uint32_t chunk_mod = 0;
index 630cce2553b9233ac31cd400260c30d6ae7504fb..3f661774b53db2772a85256304cdff4b7fb6f5d6 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -1106,7 +1106,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) {
     if (s->wrap > 0)
         s->wrap = -s->wrap; /* write the trailer only once! */
     if (s->pending == 0) {
-        Assert(s->bi_valid == 0, "bi_buf not flushed");
+        AssertHint(s->bi_valid == 0, "bi_buf not flushed");
         return Z_STREAM_END;
     }
     return Z_OK;
@@ -1274,7 +1274,7 @@ void Z_INTERNAL PREFIX(fill_window)(deflate_state *s) {
     unsigned int more;    /* Amount of free space at the end of the window. */
     unsigned int wsize = s->w_size;
 
-    Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
+    AssertHint(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
 
     do {
         more = s->window_size - s->lookahead - s->strstart;
@@ -1311,7 +1311,7 @@ void Z_INTERNAL PREFIX(fill_window)(deflate_state *s) {
          * Otherwise, window_size == 2*WSIZE so more >= 2.
          * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
          */
-        Assert(more >= 2, "more < 2");
+        AssertHint(more >= 2, "more < 2");
 
         n = PREFIX(read_buf)(s->strm, s->window + s->strstart + s->lookahead, more);
         s->lookahead += n;
index e682697d5cc51849e098635c95d5adcc24ce6e7f..bfb7d399964c346276890826bf4074fd3ce3b5e5 100644 (file)
@@ -58,8 +58,8 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
         }
 
         if (match_len >= WANT_MIN_MATCH) {
-            Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
-            Assert(s->match_start <= UINT16_MAX, "match_start should fit in uint16_t");
+            AssertHint(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
+            AssertHint(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);
index 7e5a85a95dcfc1971b967c2a4820e5a91398746c..cda681b055bead99441bf3399dfe874cbaef96f6 100644 (file)
@@ -77,8 +77,8 @@ 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
-    Assert(dist <= UINT16_MAX, "dist should fit in uint16_t");
-    Assert(len <= UINT8_MAX, "len should fit in uint8_t");
+    AssertHint(dist <= UINT16_MAX, "dist should fit in uint16_t");
+    AssertHint(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
index d5fd986d7ac6d58dee3efa062c9ee3117d891da2..03f040286ea7ff23bbbef5f6e65371b51ce5e233 100644 (file)
@@ -102,7 +102,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
                         if (UNLIKELY(match_len > STD_MAX_MATCH))
                             match_len = STD_MAX_MATCH;
 
-                        Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
+                        AssertHint(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);
index 9e39810483459931772c969455ff2c1c8c572463..c6c3d251f00f69798c2b55ded5a76ce3a93db447 100644 (file)
@@ -56,7 +56,7 @@ 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) {
-            Assert(s->strstart <= UINT16_MAX, "strstart should fit in uint16_t");
+            AssertHint(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);
index 4165eea2afe72a767c81b905d0c85bef41c5047b..ef1896c8234c86798f16aa6fdcdf3acb88ef5667 100644 (file)
@@ -78,7 +78,7 @@ 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. */
 
-            Assert((s->strstart-1) <= UINT16_MAX, "strstart-1 should fit in uint16_t");
+            AssertHint((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);
index 8303508fa120156e324daa817fc5c49d14996d6f..b9808f3f70a905ca860ef71a672a5589800940ef 100644 (file)
@@ -13,7 +13,7 @@
  * Performance tzcnt/bsf is identical on Intel cpu, tzcnt is faster than bsf on AMD cpu.
  */
 static __forceinline int __builtin_ctz(unsigned int value) {
-    Assert(value != 0, "Invalid input value: 0");
+    AssertHint(value != 0, "Invalid input value: 0");
 # if defined(X86_FEATURES) && !(_MSC_VER < 1700)
     return (int)_tzcnt_u32(value);
 # else
@@ -29,7 +29,7 @@ static __forceinline int __builtin_ctz(unsigned int value) {
  * Because of that assumption trailing_zero is not initialized and the return value is not checked.
  */
 static __forceinline int __builtin_ctzll(unsigned long long value) {
-    Assert(value != 0, "Invalid input value: 0");
+    AssertHint(value != 0, "Invalid input value: 0");
 # if defined(X86_FEATURES) && !(_MSC_VER < 1700)
     return (int)_tzcnt_u64(value);
 # else
index 2ec865dbff6c1f38090ff30d0dce159b6f1d60f1..5cea48631f70a65be6014b8985144a4e1cdfbb68 100644 (file)
@@ -311,7 +311,7 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
     strm->avail_out = (unsigned)(out < end ? (INFLATE_FAST_MIN_LEFT - 1) + (end - out)
                                            : (INFLATE_FAST_MIN_LEFT - 1) - (out - end));
 
-    Assert(bits <= 32, "Remaining bits greater than 32");
+    AssertHint(bits <= 32, "Remaining bits greater than 32");
     state->hold = (uint32_t)hold;
     state->bits = bits;
     return;
diff --git a/trees.c b/trees.c
index 9f2f49137f08a41be5f46fc70e41598cb6dedcab..49be6c48a11b57092358dfd7458a6e0cb6540688 100644 (file)
--- a/trees.c
+++ b/trees.c
@@ -490,7 +490,7 @@ static void send_tree(deflate_state *s, ct_data *tree, int max_code) {
                 send_code(s, curlen, s->bl_tree, bi_buf, bi_valid);
                 count--;
             }
-            Assert(count >= 3 && count <= 6, " 3_6?");
+            AssertHint(count >= 3 && count <= 6, " 3_6?");
             send_code(s, REP_3_6, s->bl_tree, bi_buf, bi_valid);
             send_bits(s, count-3, 2, bi_buf, bi_valid);
 
@@ -558,8 +558,8 @@ static int build_bl_tree(deflate_state *s) {
 static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes) {
     int rank;                    /* index in bl_order */
 
-    Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
-    Assert(lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, "too many codes");
+    AssertHint(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
+    AssertHint(lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, "too many codes");
 
     // Temp local variables
     uint32_t bi_valid = s->bi_valid;
@@ -811,7 +811,7 @@ void Z_INTERNAL zng_tr_flush_bits(deflate_state *s) {
 Z_INTERNAL uint16_t PREFIX(bi_reverse)(unsigned code, int len) {
     /* code: the value to invert */
     /* len: its bit length */
-    Assert(len >= 1 && len <= 15, "code length must be 1-15");
+    AssertHint(len >= 1 && len <= 15, "code length must be 1-15");
 #define bitrev8(b) \
     (uint8_t)((((uint8_t)(b) * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32)
     return (bitrev8(code >> 8) | (uint16_t)bitrev8(code) << 8) >> (16 - len);
index b5295ee4836accd423f4f7d322d9888a33cd8a37..1c2bd5e758e26ddd83167096fcdc28cb0d219319 100644 (file)
@@ -132,7 +132,7 @@ static inline uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, con
     /* Send the length code, len is the match length - STD_MIN_MATCH */
     code = zng_length_code[lc];
     c = code+LITERALS+1;
-    Assert(c < L_CODES, "bad l_code");
+    AssertHint(c < L_CODES, "bad l_code");
     send_code_trace(s, c);
 
     match_bits = ltree[c].Code;
@@ -146,7 +146,7 @@ static inline uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, con
 
     dist--; /* dist is now the match distance - 1 */
     code = d_code(dist);
-    Assert(code < D_CODES, "bad d_code");
+    AssertHint(code < D_CODES, "bad d_code");
     send_code_trace(s, code);
 
     /* Send the distance code */