]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Remove syntax, whitespace and comment differences between inflate.c
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 6 Aug 2019 10:50:57 +0000 (12:50 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 8 Aug 2019 08:21:36 +0000 (10:21 +0200)
and infback.c, making actual differences much easier to spot, easing maintenance.

infback.c
inflate.c

index 27b7b9b033ee53c164cce665dd4c9b071e14a968..50478812cdbf74358a48b77da447e9a778266e45 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -39,7 +39,7 @@ int ZEXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int windowBits, unsi
     }
     if (strm->zfree == NULL)
         strm->zfree = zng_cfree;
-    state = (struct inflate_state *)ZALLOC(strm, 1, sizeof(struct inflate_state));
+    state = (struct inflate_state *) ZALLOC(strm, 1, sizeof(struct inflate_state));
     if (state == NULL)
         return Z_MEM_ERROR;
     Tracev((stderr, "inflate: allocated\n"));
@@ -210,10 +210,8 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                 copy = state->length;
                 PULL();
                 ROOM();
-                if (copy > have)
-                    copy = have;
-                if (copy > left)
-                    copy = left;
+                if (copy > have) copy = have;
+                if (copy > left) copy = left;
                 memcpy(put, next, copy);
                 have -= copy;
                 next += copy;
@@ -242,9 +240,9 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
             }
 #endif
             Tracev((stderr, "inflate:       table sizes ok\n"));
+            state->have = 0;
 
             /* get code length code lengths (not a typo) */
-            state->have = 0;
             while (state->have < state->ncode) {
                 NEEDBITS(3);
                 state->lens[order[state->have++]] = (uint16_t)BITS(3);
@@ -253,7 +251,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
             while (state->have < 19)
                 state->lens[order[state->have++]] = 0;
             state->next = state->codes;
-            state->lencode = (code const *)(state->next);
+            state->lencode = (const code *)(state->next);
             state->lenbits = 7;
             ret = zng_inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work);
             if (ret) {
@@ -262,14 +260,13 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                 break;
             }
             Tracev((stderr, "inflate:       code lengths ok\n"));
+            state->have = 0;
 
             /* get length and distance code code lengths */
-            state->have = 0;
             while (state->have < state->nlen + state->ndist) {
                 for (;;) {
                     here = state->lencode[BITS(state->lenbits)];
-                    if (here.bits <= bits)
-                        break;
+                    if (here.bits <= bits) break;
                     PULLBYTE();
                 }
                 if (here.val < 16) {
@@ -284,7 +281,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                             state->mode = BAD;
                             break;
                         }
-                        len = (unsigned)(state->lens[state->have - 1]);
+                        len = state->lens[state->have - 1];
                         copy = 3 + BITS(2);
                         DROPBITS(2);
                     } else if (here.val == 17) {
@@ -305,8 +302,10 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                         state->mode = BAD;
                         break;
                     }
-                    while (copy--)
+                    while (copy) {
+                        --copy;
                         state->lens[state->have++] = (uint16_t)len;
+                    }
                 }
             }
 
@@ -325,7 +324,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                values here (9 and 6) without reading the comments in inftrees.h
                concerning the ENOUGH constants, which depend on those values */
             state->next = state->codes;
-            state->lencode = (code const *)(state->next);
+            state->lencode = (const code *)(state->next);
             state->lenbits = 9;
             ret = zng_inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work);
             if (ret) {
@@ -333,7 +332,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                 state->mode = BAD;
                 break;
             }
-            state->distcode = (code const *)(state->next);
+            state->distcode = (const code *)(state->next);
             state->distbits = 6;
             ret = zng_inflate_table(DISTS, state->lens + state->nlen, state->ndist,
                                 &(state->next), &(state->distbits), state->work);
@@ -367,8 +366,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
             if (here.op && (here.op & 0xf0) == 0) {
                 last = here;
                 for (;;) {
-                    here = state->lencode[last.val +
-                            (BITS(last.bits + last.op) >> last.bits)];
+                    here = state->lencode[last.val + (BITS(last.bits + last.op) >> last.bits)];
                     if ((unsigned)last.bits + (unsigned)here.bits <= bits)
                         break;
                     PULLBYTE();
@@ -379,7 +377,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
             state->length = here.val;
 
             /* process literal */
-            if (here.op == 0) {
+            if ((int)(here.op) == 0) {
                 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
                         "inflate:         literal '%c'\n" :
                         "inflate:         literal 0x%02x\n", here.val));
@@ -406,7 +404,7 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
 
             /* length code -- get extra bits, if any */
             state->extra = (here.op & 15);
-            if (state->extra != 0) {
+            if (state->extra) {
                 NEEDBITS(state->extra);
                 state->length += BITS(state->extra);
                 DROPBITS(state->extra);
@@ -437,19 +435,21 @@ int ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc
                 break;
             }
             state->offset = here.val;
+            state->extra = (here.op & 15);
 
             /* get distance extra bits, if any */
-            state->extra = (here.op & 15);
-            if (state->extra != 0) {
+            if (state->extra) {
                 NEEDBITS(state->extra);
                 state->offset += BITS(state->extra);
                 DROPBITS(state->extra);
             }
+#ifdef INFLATE_STRICT
             if (state->offset > state->wsize - (state->whave < state->wsize ? left : 0)) {
                 strm->msg = (char *)"invalid distance too far back";
                 state->mode = BAD;
                 break;
             }
+#endif
             Tracevv((stderr, "inflate:         distance %u\n", state->offset));
 
             /* copy match from window to output */
index 23e1c778f69cca03f2ffa9dd669c1547b9cb14ff..7d166567845a5f6194deb3bb6181d8e039c60732 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -564,6 +564,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             INITBITS();
             break;
 #ifdef GUNZIP
+
         case FLAGS:
             NEEDBITS(16);
             state->flags = (int)(hold);
@@ -583,6 +584,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 CRC2(state->check, hold);
             INITBITS();
             state->mode = TIME;
+
         case TIME:
             NEEDBITS(32);
             if (state->head != NULL)
@@ -591,6 +593,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 CRC4(state->check, hold);
             INITBITS();
             state->mode = OS;
+
         case OS:
             NEEDBITS(16);
             if (state->head != NULL) {
@@ -601,6 +604,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 CRC2(state->check, hold);
             INITBITS();
             state->mode = EXLEN;
+
         case EXLEN:
             if (state->flags & 0x0400) {
                 NEEDBITS(16);
@@ -614,6 +618,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 state->head->extra = NULL;
             }
             state->mode = EXTRA;
+
         case EXTRA:
             if (state->flags & 0x0400) {
                 copy = state->length;
@@ -638,6 +643,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             }
             state->length = 0;
             state->mode = NAME;
+
         case NAME:
             if (state->flags & 0x0800) {
                 if (have == 0) goto inf_leave;
@@ -658,6 +664,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             }
             state->length = 0;
             state->mode = COMMENT;
+
         case COMMENT:
             if (state->flags & 0x1000) {
                 if (have == 0) goto inf_leave;
@@ -678,6 +685,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 state->head->comment = NULL;
             }
             state->mode = HCRC;
+
         case HCRC:
             if (state->flags & 0x0200) {
                 NEEDBITS(16);
@@ -701,6 +709,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             strm->adler = state->check = ZSWAP32(hold);
             INITBITS();
             state->mode = DICT;
+
         case DICT:
             if (state->havedict == 0) {
                 RESTORE();
@@ -708,10 +717,13 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             }
             strm->adler = state->check = functable.adler32(0L, NULL, 0);
             state->mode = TYPE;
+
         case TYPE:
             if (flush == Z_BLOCK || flush == Z_TREES)
                 goto inf_leave;
+
         case TYPEDO:
+            /* determine and dispatch block type */
             INFLATE_TYPEDO_HOOK(strm, flush);  /* hook for IBM Z DFLTCC */
             if (state->last) {
                 BYTEBITS();
@@ -745,7 +757,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             }
             DROPBITS(2);
             break;
+
         case STORED:
+            /* get and verify stored block length */
             BYTEBITS();                         /* go to byte boundary */
             NEEDBITS(32);
             if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
@@ -759,9 +773,12 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             state->mode = COPY_;
             if (flush == Z_TREES)
                 goto inf_leave;
+
         case COPY_:
             state->mode = COPY;
+
         case COPY:
+            /* copy stored block from input to output */
             copy = state->length;
             if (copy) {
                 if (copy > have) copy = have;
@@ -778,7 +795,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             Tracev((stderr, "inflate:       stored end\n"));
             state->mode = TYPE;
             break;
+
         case TABLE:
+            /* get dynamic table entries descriptor */
             NEEDBITS(14);
             state->nlen = BITS(5) + 257;
             DROPBITS(5);
@@ -796,7 +815,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             Tracev((stderr, "inflate:       table sizes ok\n"));
             state->have = 0;
             state->mode = LENLENS;
+
         case LENLENS:
+            /* get code length code lengths (not a typo) */
             while (state->have < state->ncode) {
                 NEEDBITS(3);
                 state->lens[order[state->have++]] = (uint16_t)BITS(3);
@@ -816,7 +837,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             Tracev((stderr, "inflate:       code lengths ok\n"));
             state->have = 0;
             state->mode = CODELENS;
+
         case CODELENS:
+            /* get length and distance code code lengths */
             while (state->have < state->nlen + state->ndist) {
                 for (;;) {
                     here = state->lencode[BITS(state->lenbits)];
@@ -899,9 +922,12 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             state->mode = LEN_;
             if (flush == Z_TREES)
                 goto inf_leave;
+
         case LEN_:
             state->mode = LEN;
+
         case LEN:
+            /* use inflate_fast() if we have enough input and output */
             if (have >= INFLATE_FAST_MIN_HAVE &&
                 left >= INFLATE_FAST_MIN_LEFT) {
                 RESTORE();
@@ -912,6 +938,8 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 break;
             }
             state->back = 0;
+
+            /* get a literal, length, or end-of-block code */
             for (;;) {
                 here = state->lencode[BITS(state->lenbits)];
                 if (here.bits <= bits)
@@ -932,6 +960,8 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             DROPBITS(here.bits);
             state->back += here.bits;
             state->length = here.val;
+
+            /* process literal */
             if ((int)(here.op) == 0) {
                 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
                         "inflate:         literal '%c'\n" :
@@ -939,20 +969,28 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
                 state->mode = LIT;
                 break;
             }
+
+            /* process end of block */
             if (here.op & 32) {
                 Tracevv((stderr, "inflate:         end of block\n"));
                 state->back = -1;
                 state->mode = TYPE;
                 break;
             }
+
+            /* invalid code */
             if (here.op & 64) {
                 strm->msg = (char *)"invalid literal/length code";
                 state->mode = BAD;
                 break;
             }
+
+            /* length code */
             state->extra = (here.op & 15);
             state->mode = LENEXT;
+
         case LENEXT:
+            /* get extra bits, if any */
             if (state->extra) {
                 NEEDBITS(state->extra);
                 state->length += BITS(state->extra);
@@ -962,7 +1000,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             Tracevv((stderr, "inflate:         length %u\n", state->length));
             state->was = state->length;
             state->mode = DIST;
+
         case DIST:
+            /* get distance code */
             for (;;) {
                 here = state->distcode[BITS(state->distbits)];
                 if (here.bits <= bits)
@@ -990,7 +1030,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             state->offset = here.val;
             state->extra = (here.op & 15);
             state->mode = DISTEXT;
+
         case DISTEXT:
+            /* get distance extra bits, if any */
             if (state->extra) {
                 NEEDBITS(state->extra);
                 state->offset += BITS(state->extra);
@@ -1006,7 +1048,9 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
 #endif
             Tracevv((stderr, "inflate:         distance %u\n", state->offset));
             state->mode = MATCH;
+
         case MATCH:
+            /* copy match from window to output */
             if (left == 0) goto inf_leave;
             copy = out - left;
             if (state->offset > copy) {         /* copy from window */
@@ -1070,6 +1114,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             if (state->length == 0)
                 state->mode = LEN;
             break;
+
         case LIT:
             if (left == 0)
                 goto inf_leave;
@@ -1077,6 +1122,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             left--;
             state->mode = LEN;
             break;
+
         case CHECK:
             if (state->wrap) {
                 NEEDBITS(32);
@@ -1100,6 +1146,7 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             }
 #ifdef GUNZIP
             state->mode = LENGTH;
+
         case LENGTH:
             if (state->wrap && state->flags) {
                 NEEDBITS(32);
@@ -1113,16 +1160,22 @@ int ZEXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int flush) {
             }
 #endif
             state->mode = DONE;
+
         case DONE:
+            /* inflate stream terminated properly */
             ret = Z_STREAM_END;
             goto inf_leave;
+
         case BAD:
             ret = Z_DATA_ERROR;
             goto inf_leave;
+
         case MEM:
             return Z_MEM_ERROR;
+
         case SYNC:
-        default:
+
+        default:                 /* can't happen, but makes compilers happy */
             return Z_STREAM_ERROR;
         }