Lines Matching refs:state

26  * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
30 * - Add comments on state->bits assertion in inffast.c
95 local void fixedtables OF((struct inflate_state FAR *state));
106 struct inflate_state FAR *state;
108 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
109 state = (struct inflate_state FAR *)strm->state;
110 strm->total_in = strm->total_out = state->total = 0;
113 state->mode = HEAD;
114 state->last = 0;
115 state->havedict = 0;
116 state->dmax = 32768U;
117 state->head = Z_NULL;
118 state->wsize = 0;
119 state->whave = 0;
120 state->write = 0;
121 state->hold = 0;
122 state->bits = 0;
123 state->lencode = state->distcode = state->next = state->codes;
133 struct inflate_state FAR *state;
135 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
136 state = (struct inflate_state FAR *)strm->state;
137 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
139 state->hold += value << state->bits;
140 state->bits += bits;
150 struct inflate_state FAR *state;
162 state = (struct inflate_state FAR *)
164 if (state == Z_NULL) return Z_MEM_ERROR;
166 strm->state = (struct internal_state FAR *)state;
168 state->wrap = 0;
172 state->wrap = (windowBits >> 4) + 1;
178 ZFREE(strm, state);
179 strm->state = Z_NULL;
182 state->wbits = (unsigned)windowBits;
183 state->window = Z_NULL;
196 Return state with length and distance decoding tables and index sizes set to
205 local void fixedtables(state)
206 struct inflate_state FAR *state;
220 while (sym < 144) state->lens[sym++] = 8;
221 while (sym < 256) state->lens[sym++] = 9;
222 while (sym < 280) state->lens[sym++] = 7;
223 while (sym < 288) state->lens[sym++] = 8;
227 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
231 while (sym < 32) state->lens[sym++] = 5;
234 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
242 state->lencode = lenfix;
243 state->lenbits = 9;
244 state->distcode = distfix;
245 state->distbits = 5;
272 struct inflate_state state;
274 fixedtables(&state);
289 printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
290 state.lencode[low].val);
300 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
301 state.distcode[low].val);
327 struct inflate_state FAR *state;
330 state = (struct inflate_state FAR *)strm->state;
333 if (state->window == Z_NULL) {
334 state->window = (unsigned char FAR *)
335 ZALLOC(strm, 1U << state->wbits,
337 if (state->window == Z_NULL) return 1;
341 if (state->wsize == 0) {
342 state->wsize = 1U << state->wbits;
343 state->write = 0;
344 state->whave = 0;
347 /* copy state->wsize or less output bytes into the circular window */
349 if (copy >= state->wsize) {
350 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
351 state->write = 0;
352 state->whave = state->wsize;
355 dist = state->wsize - state->write;
357 zmemcpy(state->window + state->write, strm->next_out - copy, dist);
360 zmemcpy(state->window, strm->next_out - copy, copy);
361 state->write = copy;
362 state->whave = state->wsize;
365 state->write += dist;
366 if (state->write == state->wsize) state->write = 0;
367 if (state->whave < state->wsize) state->whave += dist;
378 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
402 /* Load registers with state in inflate() for speed */
409 hold = state->hold; \
410 bits = state->bits; \
413 /* Restore state from registers in inflate() */
420 state->hold = hold; \
421 state->bits = bits; \
473 inflate() uses a state machine to process as much input data and generate as
474 much output data as possible before returning. The state machine is
477 for (;;) switch (state) {
483 state = STATEm;
490 next state. The NEEDBITS() macro is usually the way the state evaluates
513 state information is maintained to continue the loop where it left off
515 would all have to actually be part of the saved state in case NEEDBITS()
524 state = STATEx;
527 As shown above, if the next state is also the next case, then the break
530 A state may also return if there is not enough output space available to
531 complete that state. Those states are copying stored data, writing a
558 struct inflate_state FAR *state;
577 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
581 state = (struct inflate_state FAR *)strm->state;
582 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
588 switch (state->mode) {
590 if (state->wrap == 0) {
591 state->mode = TYPEDO;
596 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
597 state->check = crc32(0L, Z_NULL, 0);
598 CRC2(state->check, hold);
600 state->mode = FLAGS;
603 state->flags = 0; /* expect zlib header */
604 if (state->head != Z_NULL)
605 state->head->done = -1;
606 if (!(state->wrap & 1) || /* check if zlib header allowed */
612 state->mode = BAD;
617 state->mode = BAD;
622 if (len > state->wbits) {
624 state->mode = BAD;
627 state->dmax = 1U << len;
629 strm->adler = state->check = adler32(0L, Z_NULL, 0);
630 state->mode = hold & 0x200 ? DICTID : TYPE;
636 state->flags = (int)(hold);
637 if ((state->flags & 0xff) != Z_DEFLATED) {
639 state->mode = BAD;
642 if (state->flags & 0xe000) {
644 state->mode = BAD;
647 if (state->head != Z_NULL)
648 state->head->text = (int)((hold >> 8) & 1);
649 if (state->flags & 0x0200) CRC2(state->check, hold);
651 state->mode = TIME;
654 if (state->head != Z_NULL)
655 state->head->time = hold;
656 if (state->flags & 0x0200) CRC4(state->check, hold);
658 state->mode = OS;
661 if (state->head != Z_NULL) {
662 state->head->xflags = (int)(hold & 0xff);
663 state->head->os = (int)(hold >> 8);
665 if (state->flags & 0x0200) CRC2(state->check, hold);
667 state->mode = EXLEN;
669 if (state->flags & 0x0400) {
671 state->length = (unsigned)(hold);
672 if (state->head != Z_NULL)
673 state->head->extra_len = (unsigned)hold;
674 if (state->flags & 0x0200) CRC2(state->check, hold);
677 else if (state->head != Z_NULL)
678 state->head->extra = Z_NULL;
679 state->mode = EXTRA;
681 if (state->flags & 0x0400) {
682 copy = state->length;
685 if (state->head != Z_NULL &&
686 state->head->extra != Z_NULL) {
687 len = state->head->extra_len - state->length;
688 zmemcpy(state->head->extra + len, next,
689 len + copy > state->head->extra_max ?
690 state->head->extra_max - len : copy);
692 if (state->flags & 0x0200)
693 state->check = crc32(state->check, next, copy);
696 state->length -= copy;
698 if (state->length) goto inf_leave;
700 state->length = 0;
701 state->mode = NAME;
703 if (state->flags & 0x0800) {
708 if (state->head != Z_NULL &&
709 state->head->name != Z_NULL &&
710 state->length < state->head->name_max)
711 state->head->name[state->length++] = len;
713 if (state->flags & 0x0200)
714 state->check = crc32(state->check, next, copy);
719 else if (state->head != Z_NULL)
720 state->head->name = Z_NULL;
721 state->length = 0;
722 state->mode = COMMENT;
724 if (state->flags & 0x1000) {
729 if (state->head != Z_NULL &&
730 state->head->comment != Z_NULL &&
731 state->length < state->head->comm_max)
732 state->head->comment[state->length++] = len;
734 if (state->flags & 0x0200)
735 state->check = crc32(state->check, next, copy);
740 else if (state->head != Z_NULL)
741 state->head->comment = Z_NULL;
742 state->mode = HCRC;
744 if (state->flags & 0x0200) {
746 if (hold != (state->check & 0xffff)) {
748 state->mode = BAD;
753 if (state->head != Z_NULL) {
754 state->head->hcrc = (int)((state->flags >> 9) & 1);
755 state->head->done = 1;
757 strm->adler = state->check = crc32(0L, Z_NULL, 0);
758 state->mode = TYPE;
763 strm->adler = state->check = REVERSE(hold);
765 state->mode = DICT;
767 if (state->havedict == 0) {
771 strm->adler = state->check = adler32(0L, Z_NULL, 0);
772 state->mode = TYPE;
776 if (state->last) {
778 state->mode = CHECK;
782 state->last = BITS(1);
787 state->last ? " (last)" : ""));
788 state->mode = STORED;
791 fixedtables(state);
793 state->last ? " (last)" : ""));
794 state->mode = LEN; /* decode codes */
798 state->last ? " (last)" : ""));
799 state->mode = TABLE;
803 state->mode = BAD;
812 state->mode = BAD;
815 state->length = (unsigned)hold & 0xffff;
817 state->length));
819 state->mode = COPY;
821 copy = state->length;
831 state->length -= copy;
835 state->mode = TYPE;
839 state->nlen = BITS(5) + 257;
841 state->ndist = BITS(5) + 1;
843 state->ncode = BITS(4) + 4;
846 if (state->nlen > 286 || state->ndist > 30) {
848 state->mode = BAD;
853 state->have = 0;
854 state->mode = LENLENS;
856 while (state->have < state->ncode) {
858 state->lens[order[state->have++]] = (unsigned short)BITS(3);
861 while (state->have < 19)
862 state->lens[order[state->have++]] = 0;
863 state->next = state->codes;
864 state->lencode = (code const FAR *)(state->next);
865 state->lenbits = 7;
866 ret = inflate_table(CODES, state->lens, 19, &(state->next),
867 &(state->lenbits), state->work);
870 state->mode = BAD;
874 state->have = 0;
875 state->mode = CODELENS;
877 while (state->have < state->nlen + state->ndist) {
879 this = state->lencode[BITS(state->lenbits)];
886 state->lens[state->have++] = this.val;
892 if (state->have == 0) {
894 state->mode = BAD;
897 len = state->lens[state->have - 1];
915 if (state->have + copy > state->nlen + state->ndist) {
917 state->mode = BAD;
921 state->lens[state->have++] = (unsigned short)len;
926 if (state->mode == BAD) break;
929 state->next = state->codes;
930 state->lencode = (code const FAR *)(state->next);
931 state->lenbits = 9;
932 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
933 &(state->lenbits), state->work);
936 state->mode = BAD;
939 state->distcode = (code const FAR *)(state->next);
940 state->distbits = 6;
941 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
942 &(state->next), &(state->distbits), state->work);
945 state->mode = BAD;
949 state->mode = LEN;
958 this = state->lencode[BITS(state->lenbits)];
965 this = state->lencode[last.val +
973 state->length = (unsigned)this.val;
978 state->mode = LIT;
983 state->mode = TYPE;
988 state->mode = BAD;
991 state->extra = (unsigned)(this.op) & 15;
992 state->mode = LENEXT;
994 if (state->extra) {
995 NEEDBITS(state->extra);
996 state->length += BITS(state->extra);
997 DROPBITS(state->extra);
999 Tracevv((stderr, "inflate: length %u\n", state->length));
1000 state->mode = DIST;
1003 this = state->distcode[BITS(state->distbits)];
1010 this = state->distcode[last.val +
1020 state->mode = BAD;
1023 state->offset = (unsigned)this.val;
1024 state->extra = (unsigned)(this.op) & 15;
1025 state->mode = DISTEXT;
1027 if (state->extra) {
1028 NEEDBITS(state->extra);
1029 state->offset += BITS(state->extra);
1030 DROPBITS(state->extra);
1033 if (state->offset > state->dmax) {
1035 state->mode = BAD;
1039 if (state->offset > state->whave + out - left) {
1041 state->mode = BAD;
1044 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1045 state->mode = MATCH;
1049 if (state->offset > copy) { /* copy from window */
1050 copy = state->offset - copy;
1051 if (copy > state->write) {
1052 copy -= state->write;
1053 from = state->window + (state->wsize - copy);
1056 from = state->window + (state->write - copy);
1057 if (copy > state->length) copy = state->length;
1060 from = put - state->offset;
1061 copy = state->length;
1065 state->length -= copy;
1069 if (state->length == 0) state->mode = LEN;
1073 *put++ = (unsigned char)(state->length);
1075 state->mode = LEN;
1078 if (state->wrap) {
1082 state->total += out;
1084 strm->adler = state->check =
1085 UPDATE(state->check, put - out, out);
1089 state->flags ? hold :
1091 REVERSE(hold)) != state->check) {
1093 state->mode = BAD;
1100 state->mode = LENGTH;
1102 if (state->wrap && state->flags) {
1104 if (hold != (state->total & 0xffffffffUL)) {
1106 state->mode = BAD;
1113 state->mode = DONE;
1130 error. Call updatewindow() to create and/or update the window state.
1135 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1137 state->mode = MEM;
1144 state->total += out;
1145 if (state->wrap && out)
1146 strm->adler = state->check =
1147 UPDATE(state->check, strm->next_out - out, out);
1148 strm->data_type = state->bits + (state->last ? 64 : 0) +
1149 (state->mode == TYPE ? 128 : 0);
1158 struct inflate_state FAR *state;
1159 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1161 state = (struct inflate_state FAR *)strm->state;
1162 if (state->window != Z_NULL) ZFREE(strm, state->window);
1163 ZFREE(strm, strm->state);
1164 strm->state = Z_NULL;
1174 struct inflate_state FAR *state;
1177 /* check state */
1178 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1179 state = (struct inflate_state FAR *)strm->state;
1180 if (state->wrap != 0 && state->mode != DICT)
1184 if (state->mode == DICT) {
1187 if (id != state->check)
1193 state->mode = MEM;
1196 if (dictLength > state->wsize) {
1197 zmemcpy(state->window, dictionary + dictLength - state->wsize,
1198 state->wsize);
1199 state->whave = state->wsize;
1202 zmemcpy(state->window + state->wsize - dictLength, dictionary,
1204 state->whave = dictLength;
1206 state->havedict = 1;
1215 struct inflate_state FAR *state;
1217 /* check state */
1218 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1219 state = (struct inflate_state FAR *)strm->state;
1220 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1223 state->head = head;
1232 state. If on return *have equals four, then the pattern was found and the
1236 called again with more data and the *have state. *have is initialized to
1268 struct inflate_state FAR *state;
1271 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1272 state = (struct inflate_state FAR *)strm->state;
1273 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1276 if (state->mode != SYNC) {
1277 state->mode = SYNC;
1278 state->hold <<= state->bits & 7;
1279 state->bits -= state->bits & 7;
1281 while (state->bits >= 8) {
1282 buf[len++] = (unsigned char)(state->hold);
1283 state->hold >>= 8;
1284 state->bits -= 8;
1286 state->have = 0;
1287 syncsearch(&(state->have), buf, len);
1291 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1297 if (state->have != 4) return Z_DATA_ERROR;
1301 state->mode = TYPE;
1316 struct inflate_state FAR *state;
1318 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1319 state = (struct inflate_state FAR *)strm->state;
1320 return state->mode == STORED && state->bits == 0;
1327 struct inflate_state FAR *state;
1333 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1336 state = (struct inflate_state FAR *)source->state;
1343 if (state->window != Z_NULL) {
1345 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1352 /* copy state */
1354 zmemcpy(copy, state, sizeof(struct inflate_state));
1355 if (state->lencode >= state->codes &&
1356 state->lencode <= state->codes + ENOUGH - 1) {
1357 copy->lencode = copy->codes + (state->lencode - state->codes);
1358 copy->distcode = copy->codes + (state->distcode - state->codes);
1360 copy->next = copy->codes + (state->next - state->codes);
1362 wsize = 1U << state->wbits;
1363 zmemcpy(window, state->window, wsize);
1366 dest->state = (struct internal_state FAR *)copy;