]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Clean up the use of switch cases. develop
authorMark Adler <git@madler.net>
Sat, 4 Apr 2026 01:47:11 +0000 (18:47 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 29 Jul 2026 09:53:07 +0000 (11:53 +0200)
Use default for exhaustive cases, initialize variables at declaration,
and remove dummy assignments in inftrees.c.

Upstream: https://github.com/madler/zlib/commit/fb8dd62f

infback.c
inflate.c
inftrees.c

index cc914830aa45c195e7db14106092d5c4279f2240..4aad05cf889d6c35a5ec20df6111c923d778f0ac 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -208,7 +208,7 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in
                 Tracev((stderr, "inflate:     dynamic codes block%s\n", state->last ? " (last)" : ""));
                 state->mode = TABLE;
                 break;
-            case 3:
+            default:
                 SET_BAD("invalid block type");
             }
             DROPBITS(2);
index a05f292a88bcfe1cae99ab36d095781029627c10..1bb35bf8151000b766ebb824bd5c605c2bb14b29 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -752,7 +752,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
                 Tracev((stderr, "inflate:     dynamic codes block%s\n", state->last ? " (last)" : ""));
                 state->mode = TABLE;
                 break;
-            case 3:
+            default:
                 SET_BAD("invalid block type");
             }
             DROPBITS(2);
index d6bdf3583a6620d41a30b5a55e49f230a905c2d5..763e8d2284a87a9a83714899126c257779081ca4 100644 (file)
@@ -144,27 +144,27 @@ static inline void count_lengths(uint16_t *lens, int codes, uint16_t *count) {
  */
 int Z_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes,
                                  code * *table, unsigned *bits, uint16_t *work) {
-    unsigned len;               /* a code's length in bits */
-    unsigned sym;               /* index of code symbols */
-    unsigned min, max;          /* minimum and maximum code lengths */
-    unsigned root;              /* number of index bits for root table */
-    unsigned curr;              /* number of index bits for current table */
-    unsigned drop;              /* code bits to drop for sub-table */
-    int left;                   /* number of prefix codes available */
-    unsigned used;              /* code entries in table used */
-    uint16_t rhuff;             /* Reversed huffman code */
-    unsigned huff;              /* Huffman code */
-    unsigned incr;              /* for incrementing code, index */
-    unsigned fill;              /* index for replicating entries */
-    unsigned low;               /* low bits for current root entry */
-    unsigned mask;              /* mask for low root bits */
-    code here;                  /* table entry for duplication */
-    code *next;                 /* next available space in table */
-    const uint16_t *base;       /* base value table to use */
-    const uint16_t *extra;      /* extra bits table to use */
-    unsigned match;             /* use base and extra for symbol >= match */
+    unsigned len;                 /* a code's length in bits */
+    unsigned sym;                 /* index of code symbols */
+    unsigned min, max;            /* minimum and maximum code lengths */
+    unsigned root;                /* number of index bits for root table */
+    unsigned curr;                /* number of index bits for current table */
+    unsigned drop;                /* code bits to drop for sub-table */
+    int left;                     /* number of prefix codes available */
+    unsigned used;                /* code entries in table used */
+    uint16_t rhuff;               /* Reversed huffman code */
+    unsigned huff;                /* Huffman code */
+    unsigned incr;                /* for incrementing code, index */
+    unsigned fill;                /* index for replicating entries */
+    unsigned low;                 /* low bits for current root entry */
+    unsigned mask;                /* mask for low root bits */
+    code here;                    /* table entry for duplication */
+    code *next;                   /* next available space in table */
+    const uint16_t *base = NULL;  /* base value table to use */
+    const uint16_t *extra = NULL; /* extra bits table to use */
+    unsigned match = 0;           /* use base and extra for symbol >= match */
     uint16_t ALIGNED_(16) count[MAX_BITS+1]; /* number of codes of each length */
-    uint16_t offs[MAX_BITS+1];  /* offsets in table for each length */
+    uint16_t offs[MAX_BITS+1];    /* offsets in table for each length */
     static const uint16_t lbase[31] = { /* Length codes 257..285 base */
         3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
@@ -296,10 +296,9 @@ int Z_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes,
         extra = lext;
         match = 257;
         break;
-    default:    /* DISTS */
+    case DISTS:
         base = dbase;
         extra = dext;
-        match = 0;
     }
 
     /* initialize state for loop */