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->wnext = 0;
121 state->hold = 0;
122 state->bits = 0;
123 state->lencode = state->distcode = state->next = state->codes;
124 state->sane = 1;
125 state->back = -1;
135 struct inflate_state FAR *state;
137 /* get the state */
138 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
139 state = (struct inflate_state FAR *)strm->state;
157 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
158 ZFREE(strm, state->window);
159 state->window = Z_NULL;
162 /* update state and reset the rest of it */
163 state->wrap = wrap;
164 state->wbits = (unsigned)windowBits;
175 struct inflate_state FAR *state;
187 state = (struct inflate_state FAR *)
189 if (state == Z_NULL) return Z_MEM_ERROR;
191 strm->state = (struct internal_state FAR *)state;
192 state->window = Z_NULL;
195 ZFREE(strm, state);
196 strm->state = Z_NULL;
214 struct inflate_state FAR *state;
216 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
217 state = (struct inflate_state FAR *)strm->state;
219 state->hold = 0;
220 state->bits = 0;
223 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
225 state->hold += value << state->bits;
226 state->bits += bits;
231 Return state with length and distance decoding tables and index sizes set to
240 local void fixedtables(state)
241 struct inflate_state FAR *state;
255 while (sym < 144) state->lens[sym++] = 8;
256 while (sym < 256) state->lens[sym++] = 9;
257 while (sym < 280) state->lens[sym++] = 7;
258 while (sym < 288) state->lens[sym++] = 8;
262 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
266 while (sym < 32) state->lens[sym++] = 5;
269 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
277 state->lencode = lenfix;
278 state->lenbits = 9;
279 state->distcode = distfix;
280 state->distbits = 5;
307 struct inflate_state state;
309 fixedtables(&state);
324 printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
325 state.lencode[low].val);
335 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
336 state.distcode[low].val);
362 struct inflate_state FAR *state;
365 state = (struct inflate_state FAR *)strm->state;
368 if (state->window == Z_NULL) {
369 state->window = (unsigned char FAR *)
370 ZALLOC(strm, 1U << state->wbits,
372 if (state->window == Z_NULL) return 1;
376 if (state->wsize == 0) {
377 state->wsize = 1U << state->wbits;
378 state->wnext = 0;
379 state->whave = 0;
382 /* copy state->wsize or less output bytes into the circular window */
384 if (copy >= state->wsize) {
385 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
386 state->wnext = 0;
387 state->whave = state->wsize;
390 dist = state->wsize - state->wnext;
392 zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
395 zmemcpy(state->window, strm->next_out - copy, copy);
396 state->wnext = copy;
397 state->whave = state->wsize;
400 state->wnext += dist;
401 if (state->wnext == state->wsize) state->wnext = 0;
402 if (state->whave < state->wsize) state->whave += dist;
413 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
437 /* Load registers with state in inflate() for speed */
444 hold = state->hold; \
445 bits = state->bits; \
448 /* Restore state from registers in inflate() */
455 state->hold = hold; \
456 state->bits = bits; \
508 inflate() uses a state machine to process as much input data and generate as
509 much output data as possible before returning. The state machine is
512 for (;;) switch (state) {
518 state = STATEm;
525 next state. The NEEDBITS() macro is usually the way the state evaluates
548 state information is maintained to continue the loop where it left off
550 would all have to actually be part of the saved state in case NEEDBITS()
559 state = STATEx;
562 As shown above, if the next state is also the next case, then the break
565 A state may also return if there is not enough output space available to
566 complete that state. Those states are copying stored data, writing a
593 struct inflate_state FAR *state;
612 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
616 state = (struct inflate_state FAR *)strm->state;
617 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
623 switch (state->mode) {
625 if (state->wrap == 0) {
626 state->mode = TYPEDO;
631 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
632 state->check = crc32(0L, Z_NULL, 0);
633 CRC2(state->check, hold);
635 state->mode = FLAGS;
638 state->flags = 0; /* expect zlib header */
639 if (state->head != Z_NULL)
640 state->head->done = -1;
641 if (!(state->wrap & 1) || /* check if zlib header allowed */
647 state->mode = BAD;
652 state->mode = BAD;
657 if (state->wbits == 0)
658 state->wbits = len;
659 else if (len > state->wbits) {
661 state->mode = BAD;
664 state->dmax = 1U << len;
666 strm->adler = state->check = adler32(0L, Z_NULL, 0);
667 state->mode = hold & 0x200 ? DICTID : TYPE;
673 state->flags = (int)(hold);
674 if ((state->flags & 0xff) != Z_DEFLATED) {
676 state->mode = BAD;
679 if (state->flags & 0xe000) {
681 state->mode = BAD;
684 if (state->head != Z_NULL)
685 state->head->text = (int)((hold >> 8) & 1);
686 if (state->flags & 0x0200) CRC2(state->check, hold);
688 state->mode = TIME;
691 if (state->head != Z_NULL)
692 state->head->time = hold;
693 if (state->flags & 0x0200) CRC4(state->check, hold);
695 state->mode = OS;
698 if (state->head != Z_NULL) {
699 state->head->xflags = (int)(hold & 0xff);
700 state->head->os = (int)(hold >> 8);
702 if (state->flags & 0x0200) CRC2(state->check, hold);
704 state->mode = EXLEN;
706 if (state->flags & 0x0400) {
708 state->length = (unsigned)(hold);
709 if (state->head != Z_NULL)
710 state->head->extra_len = (unsigned)hold;
711 if (state->flags & 0x0200) CRC2(state->check, hold);
714 else if (state->head != Z_NULL)
715 state->head->extra = Z_NULL;
716 state->mode = EXTRA;
718 if (state->flags & 0x0400) {
719 copy = state->length;
722 if (state->head != Z_NULL &&
723 state->head->extra != Z_NULL) {
724 len = state->head->extra_len - state->length;
725 zmemcpy(state->head->extra + len, next,
726 len + copy > state->head->extra_max ?
727 state->head->extra_max - len : copy);
729 if (state->flags & 0x0200)
730 state->check = crc32(state->check, next, copy);
733 state->length -= copy;
735 if (state->length) goto inf_leave;
737 state->length = 0;
738 state->mode = NAME;
740 if (state->flags & 0x0800) {
745 if (state->head != Z_NULL &&
746 state->head->name != Z_NULL &&
747 state->length < state->head->name_max)
748 state->head->name[state->length++] = len;
750 if (state->flags & 0x0200)
751 state->check = crc32(state->check, next, copy);
756 else if (state->head != Z_NULL)
757 state->head->name = Z_NULL;
758 state->length = 0;
759 state->mode = COMMENT;
761 if (state->flags & 0x1000) {
766 if (state->head != Z_NULL &&
767 state->head->comment != Z_NULL &&
768 state->length < state->head->comm_max)
769 state->head->comment[state->length++] = len;
771 if (state->flags & 0x0200)
772 state->check = crc32(state->check, next, copy);
777 else if (state->head != Z_NULL)
778 state->head->comment = Z_NULL;
779 state->mode = HCRC;
781 if (state->flags & 0x0200) {
783 if (hold != (state->check & 0xffff)) {
785 state->mode = BAD;
790 if (state->head != Z_NULL) {
791 state->head->hcrc = (int)((state->flags >> 9) & 1);
792 state->head->done = 1;
794 strm->adler = state->check = crc32(0L, Z_NULL, 0);
795 state->mode = TYPE;
800 strm->adler = state->check = REVERSE(hold);
802 state->mode = DICT;
804 if (state->havedict == 0) {
808 strm->adler = state->check = adler32(0L, Z_NULL, 0);
809 state->mode = TYPE;
813 if (state->last) {
815 state->mode = CHECK;
819 state->last = BITS(1);
824 state->last ? " (last)" : ""));
825 state->mode = STORED;
828 fixedtables(state);
830 state->last ? " (last)" : ""));
831 state->mode = LEN_; /* decode codes */
839 state->last ? " (last)" : ""));
840 state->mode = TABLE;
844 state->mode = BAD;
853 state->mode = BAD;
856 state->length = (unsigned)hold & 0xffff;
858 state->length));
860 state->mode = COPY_;
863 state->mode = COPY;
865 copy = state->length;
875 state->length -= copy;
879 state->mode = TYPE;
883 state->nlen = BITS(5) + 257;
885 state->ndist = BITS(5) + 1;
887 state->ncode = BITS(4) + 4;
890 if (state->nlen > 286 || state->ndist > 30) {
892 state->mode = BAD;
897 state->have = 0;
898 state->mode = LENLENS;
900 while (state->have < state->ncode) {
902 state->lens[order[state->have++]] = (unsigned short)BITS(3);
905 while (state->have < 19)
906 state->lens[order[state->have++]] = 0;
907 state->next = state->codes;
908 state->lencode = (code const FAR *)(state->next);
909 state->lenbits = 7;
910 ret = inflate_table(CODES, state->lens, 19, &(state->next),
911 &(state->lenbits), state->work);
914 state->mode = BAD;
918 state->have = 0;
919 state->mode = CODELENS;
921 while (state->have < state->nlen + state->ndist) {
923 here = state->lencode[BITS(state->lenbits)];
930 state->lens[state->have++] = here.val;
936 if (state->have == 0) {
938 state->mode = BAD;
941 len = state->lens[state->have - 1];
959 if (state->have + copy > state->nlen + state->ndist) {
961 state->mode = BAD;
965 state->lens[state->have++] = (unsigned short)len;
970 if (state->mode == BAD) break;
973 if (state->lens[256] == 0) {
975 state->mode = BAD;
982 state->next = state->codes;
983 state->lencode = (code const FAR *)(state->next);
984 state->lenbits = 9;
985 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
986 &(state->lenbits), state->work);
989 state->mode = BAD;
992 state->distcode = (code const FAR *)(state->next);
993 state->distbits = 6;
994 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
995 &(state->next), &(state->distbits), state->work);
998 state->mode = BAD;
1002 state->mode = LEN_;
1005 state->mode = LEN;
1011 if (state->mode == TYPE)
1012 state->back = -1;
1015 state->back = 0;
1017 here = state->lencode[BITS(state->lenbits)];
1024 here = state->lencode[last.val +
1030 state->back += last.bits;
1033 state->back += here.bits;
1034 state->length = (unsigned)here.val;
1039 state->mode = LIT;
1044 state->back = -1;
1045 state->mode = TYPE;
1050 state->mode = BAD;
1053 state->extra = (unsigned)(here.op) & 15;
1054 state->mode = LENEXT;
1056 if (state->extra) {
1057 NEEDBITS(state->extra);
1058 state->length += BITS(state->extra);
1059 DROPBITS(state->extra);
1060 state->back += state->extra;
1062 Tracevv((stderr, "inflate: length %u\n", state->length));
1063 state->was = state->length;
1064 state->mode = DIST;
1067 here = state->distcode[BITS(state->distbits)];
1074 here = state->distcode[last.val +
1080 state->back += last.bits;
1083 state->back += here.bits;
1086 state->mode = BAD;
1089 state->offset = (unsigned)here.val;
1090 state->extra = (unsigned)(here.op) & 15;
1091 state->mode = DISTEXT;
1093 if (state->extra) {
1094 NEEDBITS(state->extra);
1095 state->offset += BITS(state->extra);
1096 DROPBITS(state->extra);
1097 state->back += state->extra;
1100 if (state->offset > state->dmax) {
1102 state->mode = BAD;
1106 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1107 state->mode = MATCH;
1111 if (state->offset > copy) { /* copy from window */
1112 copy = state->offset - copy;
1113 if (copy > state->whave) {
1114 if (state->sane) {
1116 state->mode = BAD;
1121 copy -= state->whave;
1122 if (copy > state->length) copy = state->length;
1125 state->length -= copy;
1129 if (state->length == 0) state->mode = LEN;
1133 if (copy > state->wnext) {
1134 copy -= state->wnext;
1135 from = state->window + (state->wsize - copy);
1138 from = state->window + (state->wnext - copy);
1139 if (copy > state->length) copy = state->length;
1142 from = put - state->offset;
1143 copy = state->length;
1147 state->length -= copy;
1151 if (state->length == 0) state->mode = LEN;
1155 *put++ = (unsigned char)(state->length);
1157 state->mode = LEN;
1160 if (state->wrap) {
1164 state->total += out;
1166 strm->adler = state->check =
1167 UPDATE(state->check, put - out, out);
1171 state->flags ? hold :
1173 REVERSE(hold)) != state->check) {
1175 state->mode = BAD;
1182 state->mode = LENGTH;
1184 if (state->wrap && state->flags) {
1186 if (hold != (state->total & 0xffffffffUL)) {
1188 state->mode = BAD;
1195 state->mode = DONE;
1212 error. Call updatewindow() to create and/or update the window state.
1217 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1219 state->mode = MEM;
1226 state->total += out;
1227 if (state->wrap && out)
1228 strm->adler = state->check =
1229 UPDATE(state->check, strm->next_out - out, out);
1230 strm->data_type = state->bits + (state->last ? 64 : 0) +
1231 (state->mode == TYPE ? 128 : 0) +
1232 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1241 struct inflate_state FAR *state;
1242 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1244 state = (struct inflate_state FAR *)strm->state;
1245 if (state->window != Z_NULL) ZFREE(strm, state->window);
1246 ZFREE(strm, strm->state);
1247 strm->state = Z_NULL;
1257 struct inflate_state FAR *state;
1260 /* check state */
1261 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1262 state = (struct inflate_state FAR *)strm->state;
1263 if (state->wrap != 0 && state->mode != DICT)
1267 if (state->mode == DICT) {
1270 if (id != state->check)
1276 state->mode = MEM;
1279 if (dictLength > state->wsize) {
1280 zmemcpy(state->window, dictionary + dictLength - state->wsize,
1281 state->wsize);
1282 state->whave = state->wsize;
1285 zmemcpy(state->window + state->wsize - dictLength, dictionary,
1287 state->whave = dictLength;
1289 state->havedict = 1;
1298 struct inflate_state FAR *state;
1300 /* check state */
1301 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1302 state = (struct inflate_state FAR *)strm->state;
1303 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1306 state->head = head;
1315 state. If on return *have equals four, then the pattern was found and the
1319 called again with more data and the *have state. *have is initialized to
1351 struct inflate_state FAR *state;
1354 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1355 state = (struct inflate_state FAR *)strm->state;
1356 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1359 if (state->mode != SYNC) {
1360 state->mode = SYNC;
1361 state->hold <<= state->bits & 7;
1362 state->bits -= state->bits & 7;
1364 while (state->bits >= 8) {
1365 buf[len++] = (unsigned char)(state->hold);
1366 state->hold >>= 8;
1367 state->bits -= 8;
1369 state->have = 0;
1370 syncsearch(&(state->have), buf, len);
1374 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1380 if (state->have != 4) return Z_DATA_ERROR;
1384 state->mode = TYPE;
1399 struct inflate_state FAR *state;
1401 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1402 state = (struct inflate_state FAR *)strm->state;
1403 return state->mode == STORED && state->bits == 0;
1410 struct inflate_state FAR *state;
1416 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1419 state = (struct inflate_state FAR *)source->state;
1426 if (state->window != Z_NULL) {
1428 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1435 /* copy state */
1437 zmemcpy(copy, state, sizeof(struct inflate_state));
1438 if (state->lencode >= state->codes &&
1439 state->lencode <= state->codes + ENOUGH - 1) {
1440 copy->lencode = copy->codes + (state->lencode - state->codes);
1441 copy->distcode = copy->codes + (state->distcode - state->codes);
1443 copy->next = copy->codes + (state->next - state->codes);
1445 wsize = 1U << state->wbits;
1446 zmemcpy(window, state->window, wsize);
1449 dest->state = (struct internal_state FAR *)copy;
1457 struct inflate_state FAR *state;
1459 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1460 state = (struct inflate_state FAR *)strm->state;
1461 state->sane = !subvert;
1465 state->sane = 1;
1473 struct inflate_state FAR *state;
1475 if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1476 state = (struct inflate_state FAR *)strm->state;
1477 return ((long)(state->back) << 16) +
1478 (state->mode == COPY ? state->length :
1479 (state->mode == MATCH ? state->was - state->length : 0));