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;
112 if (state->wrap) /* to support ill-conceived Java test suite */
113 strm->adler = state->wrap & 1;
114 state->mode = HEAD;
115 state->last = 0;
116 state->havedict = 0;
117 state->dmax = 32768U;
118 state->head = Z_NULL;
119 state->hold = 0;
120 state->bits = 0;
121 state->lencode = state->distcode = state->next = state->codes;
122 state->sane = 1;
123 state->back = -1;
131 struct inflate_state FAR *state;
133 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
134 state = (struct inflate_state FAR *)strm->state;
135 state->wsize = 0;
136 state->whave = 0;
137 state->wnext = 0;
146 struct inflate_state FAR *state;
148 /* get the state */
149 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
150 state = (struct inflate_state FAR *)strm->state;
168 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
169 ZFREE(strm, state->window);
170 state->window = Z_NULL;
173 /* update state and reset the rest of it */
174 state->wrap = wrap;
175 state->wbits = (unsigned)windowBits;
186 struct inflate_state FAR *state;
207 state = (struct inflate_state FAR *)
209 if (state == Z_NULL) return Z_MEM_ERROR;
211 strm->state = (struct internal_state FAR *)state;
212 state->window = Z_NULL;
215 ZFREE(strm, state);
216 strm->state = Z_NULL;
234 struct inflate_state FAR *state;
236 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
237 state = (struct inflate_state FAR *)strm->state;
239 state->hold = 0;
240 state->bits = 0;
243 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
245 state->hold += value << state->bits;
246 state->bits += bits;
251 Return state with length and distance decoding tables and index sizes set to
260 local void fixedtables(state)
261 struct inflate_state FAR *state;
275 while (sym < 144) state->lens[sym++] = 8;
276 while (sym < 256) state->lens[sym++] = 9;
277 while (sym < 280) state->lens[sym++] = 7;
278 while (sym < 288) state->lens[sym++] = 8;
282 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
286 while (sym < 32) state->lens[sym++] = 5;
289 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
297 state->lencode = lenfix;
298 state->lenbits = 9;
299 state->distcode = distfix;
300 state->distbits = 5;
327 struct inflate_state state;
329 fixedtables(&state);
344 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
345 state.lencode[low].bits, state.lencode[low].val);
355 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
356 state.distcode[low].val);
382 struct inflate_state FAR *state;
385 state = (struct inflate_state FAR *)strm->state;
388 if (state->window == Z_NULL) {
389 state->window = (unsigned char FAR *)
390 ZALLOC(strm, 1U << state->wbits,
392 if (state->window == Z_NULL) return 1;
396 if (state->wsize == 0) {
397 state->wsize = 1U << state->wbits;
398 state->wnext = 0;
399 state->whave = 0;
402 /* copy state->wsize or less output bytes into the circular window */
404 if (copy >= state->wsize) {
405 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
406 state->wnext = 0;
407 state->whave = state->wsize;
410 dist = state->wsize - state->wnext;
412 zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
415 zmemcpy(state->window, strm->next_out - copy, copy);
416 state->wnext = copy;
417 state->whave = state->wsize;
420 state->wnext += dist;
421 if (state->wnext == state->wsize) state->wnext = 0;
422 if (state->whave < state->wsize) state->whave += dist;
433 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
457 /* Load registers with state in inflate() for speed */
464 hold = state->hold; \
465 bits = state->bits; \
468 /* Restore state from registers in inflate() */
475 state->hold = hold; \
476 state->bits = bits; \
528 inflate() uses a state machine to process as much input data and generate as
529 much output data as possible before returning. The state machine is
532 for (;;) switch (state) {
538 state = STATEm;
545 next state. The NEEDBITS() macro is usually the way the state evaluates
568 state information is maintained to continue the loop where it left off
570 would all have to actually be part of the saved state in case NEEDBITS()
579 state = STATEx;
582 As shown above, if the next state is also the next case, then the break
585 A state may also return if there is not enough output space available to
586 complete that state. Those states are copying stored data, writing a
613 struct inflate_state FAR *state;
632 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
636 state = (struct inflate_state FAR *)strm->state;
637 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
643 switch (state->mode) {
645 if (state->wrap == 0) {
646 state->mode = TYPEDO;
651 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
652 state->check = crc32(0L, Z_NULL, 0);
653 CRC2(state->check, hold);
655 state->mode = FLAGS;
658 state->flags = 0; /* expect zlib header */
659 if (state->head != Z_NULL)
660 state->head->done = -1;
661 if (!(state->wrap & 1) || /* check if zlib header allowed */
667 state->mode = BAD;
672 state->mode = BAD;
677 if (state->wbits == 0)
678 state->wbits = len;
679 else if (len > state->wbits) {
681 state->mode = BAD;
684 state->dmax = 1U << len;
686 strm->adler = state->check = adler32(0L, Z_NULL, 0);
687 state->mode = hold & 0x200 ? DICTID : TYPE;
693 state->flags = (int)(hold);
694 if ((state->flags & 0xff) != Z_DEFLATED) {
696 state->mode = BAD;
699 if (state->flags & 0xe000) {
701 state->mode = BAD;
704 if (state->head != Z_NULL)
705 state->head->text = (int)((hold >> 8) & 1);
706 if (state->flags & 0x0200) CRC2(state->check, hold);
708 state->mode = TIME;
711 if (state->head != Z_NULL)
712 state->head->time = hold;
713 if (state->flags & 0x0200) CRC4(state->check, hold);
715 state->mode = OS;
718 if (state->head != Z_NULL) {
719 state->head->xflags = (int)(hold & 0xff);
720 state->head->os = (int)(hold >> 8);
722 if (state->flags & 0x0200) CRC2(state->check, hold);
724 state->mode = EXLEN;
726 if (state->flags & 0x0400) {
728 state->length = (unsigned)(hold);
729 if (state->head != Z_NULL)
730 state->head->extra_len = (unsigned)hold;
731 if (state->flags & 0x0200) CRC2(state->check, hold);
734 else if (state->head != Z_NULL)
735 state->head->extra = Z_NULL;
736 state->mode = EXTRA;
738 if (state->flags & 0x0400) {
739 copy = state->length;
742 if (state->head != Z_NULL &&
743 state->head->extra != Z_NULL) {
744 len = state->head->extra_len - state->length;
745 zmemcpy(state->head->extra + len, next,
746 len + copy > state->head->extra_max ?
747 state->head->extra_max - len : copy);
749 if (state->flags & 0x0200)
750 state->check = crc32(state->check, next, copy);
753 state->length -= copy;
755 if (state->length) goto inf_leave;
757 state->length = 0;
758 state->mode = NAME;
760 if (state->flags & 0x0800) {
765 if (state->head != Z_NULL &&
766 state->head->name != Z_NULL &&
767 state->length < state->head->name_max)
768 state->head->name[state->length++] = len;
770 if (state->flags & 0x0200)
771 state->check = crc32(state->check, next, copy);
776 else if (state->head != Z_NULL)
777 state->head->name = Z_NULL;
778 state->length = 0;
779 state->mode = COMMENT;
781 if (state->flags & 0x1000) {
786 if (state->head != Z_NULL &&
787 state->head->comment != Z_NULL &&
788 state->length < state->head->comm_max)
789 state->head->comment[state->length++] = len;
791 if (state->flags & 0x0200)
792 state->check = crc32(state->check, next, copy);
797 else if (state->head != Z_NULL)
798 state->head->comment = Z_NULL;
799 state->mode = HCRC;
801 if (state->flags & 0x0200) {
803 if (hold != (state->check & 0xffff)) {
805 state->mode = BAD;
810 if (state->head != Z_NULL) {
811 state->head->hcrc = (int)((state->flags >> 9) & 1);
812 state->head->done = 1;
814 strm->adler = state->check = crc32(0L, Z_NULL, 0);
815 state->mode = TYPE;
820 strm->adler = state->check = REVERSE(hold);
822 state->mode = DICT;
824 if (state->havedict == 0) {
828 strm->adler = state->check = adler32(0L, Z_NULL, 0);
829 state->mode = TYPE;
833 if (state->last) {
835 state->mode = CHECK;
839 state->last = BITS(1);
844 state->last ? " (last)" : ""));
845 state->mode = STORED;
848 fixedtables(state);
850 state->last ? " (last)" : ""));
851 state->mode = LEN_; /* decode codes */
859 state->last ? " (last)" : ""));
860 state->mode = TABLE;
864 state->mode = BAD;
873 state->mode = BAD;
876 state->length = (unsigned)hold & 0xffff;
878 state->length));
880 state->mode = COPY_;
883 state->mode = COPY;
885 copy = state->length;
895 state->length -= copy;
899 state->mode = TYPE;
903 state->nlen = BITS(5) + 257;
905 state->ndist = BITS(5) + 1;
907 state->ncode = BITS(4) + 4;
910 if (state->nlen > 286 || state->ndist > 30) {
912 state->mode = BAD;
917 state->have = 0;
918 state->mode = LENLENS;
920 while (state->have < state->ncode) {
922 state->lens[order[state->have++]] = (unsigned short)BITS(3);
925 while (state->have < 19)
926 state->lens[order[state->have++]] = 0;
927 state->next = state->codes;
928 state->lencode = (code const FAR *)(state->next);
929 state->lenbits = 7;
930 ret = inflate_table(CODES, state->lens, 19, &(state->next),
931 &(state->lenbits), state->work);
934 state->mode = BAD;
938 state->have = 0;
939 state->mode = CODELENS;
941 while (state->have < state->nlen + state->ndist) {
943 here = state->lencode[BITS(state->lenbits)];
949 state->lens[state->have++] = here.val;
955 if (state->have == 0) {
957 state->mode = BAD;
960 len = state->lens[state->have - 1];
978 if (state->have + copy > state->nlen + state->ndist) {
980 state->mode = BAD;
984 state->lens[state->have++] = (unsigned short)len;
989 if (state->mode == BAD) break;
992 if (state->lens[256] == 0) {
994 state->mode = BAD;
1001 state->next = state->codes;
1002 state->lencode = (code const FAR *)(state->next);
1003 state->lenbits = 9;
1004 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1005 &(state->lenbits), state->work);
1008 state->mode = BAD;
1011 state->distcode = (code const FAR *)(state->next);
1012 state->distbits = 6;
1013 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1014 &(state->next), &(state->distbits), state->work);
1017 state->mode = BAD;
1021 state->mode = LEN_;
1024 state->mode = LEN;
1030 if (state->mode == TYPE)
1031 state->back = -1;
1034 state->back = 0;
1036 here = state->lencode[BITS(state->lenbits)];
1043 here = state->lencode[last.val +
1049 state->back += last.bits;
1052 state->back += here.bits;
1053 state->length = (unsigned)here.val;
1058 state->mode = LIT;
1063 state->back = -1;
1064 state->mode = TYPE;
1069 state->mode = BAD;
1072 state->extra = (unsigned)(here.op) & 15;
1073 state->mode = LENEXT;
1075 if (state->extra) {
1076 NEEDBITS(state->extra);
1077 state->length += BITS(state->extra);
1078 DROPBITS(state->extra);
1079 state->back += state->extra;
1081 Tracevv((stderr, "inflate: length %u\n", state->length));
1082 state->was = state->length;
1083 state->mode = DIST;
1086 here = state->distcode[BITS(state->distbits)];
1093 here = state->distcode[last.val +
1099 state->back += last.bits;
1102 state->back += here.bits;
1105 state->mode = BAD;
1108 state->offset = (unsigned)here.val;
1109 state->extra = (unsigned)(here.op) & 15;
1110 state->mode = DISTEXT;
1112 if (state->extra) {
1113 NEEDBITS(state->extra);
1114 state->offset += BITS(state->extra);
1115 DROPBITS(state->extra);
1116 state->back += state->extra;
1119 if (state->offset > state->dmax) {
1121 state->mode = BAD;
1125 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1126 state->mode = MATCH;
1130 if (state->offset > copy) { /* copy from window */
1131 copy = state->offset - copy;
1132 if (copy > state->whave) {
1133 if (state->sane) {
1135 state->mode = BAD;
1140 copy -= state->whave;
1141 if (copy > state->length) copy = state->length;
1144 state->length -= copy;
1148 if (state->length == 0) state->mode = LEN;
1152 if (copy > state->wnext) {
1153 copy -= state->wnext;
1154 from = state->window + (state->wsize - copy);
1157 from = state->window + (state->wnext - copy);
1158 if (copy > state->length) copy = state->length;
1161 from = put - state->offset;
1162 copy = state->length;
1166 state->length -= copy;
1170 if (state->length == 0) state->mode = LEN;
1174 *put++ = (unsigned char)(state->length);
1176 state->mode = LEN;
1179 if (state->wrap) {
1183 state->total += out;
1185 strm->adler = state->check =
1186 UPDATE(state->check, put - out, out);
1190 state->flags ? hold :
1192 REVERSE(hold)) != state->check) {
1194 state->mode = BAD;
1201 state->mode = LENGTH;
1203 if (state->wrap && state->flags) {
1205 if (hold != (state->total & 0xffffffffUL)) {
1207 state->mode = BAD;
1214 state->mode = DONE;
1231 error. Call updatewindow() to create and/or update the window state.
1236 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1237 (state->mode < CHECK || flush != Z_FINISH)))
1239 state->mode = MEM;
1246 state->total += out;
1247 if (state->wrap && out)
1248 strm->adler = state->check =
1249 UPDATE(state->check, strm->next_out - out, out);
1250 strm->data_type = state->bits + (state->last ? 64 : 0) +
1251 (state->mode == TYPE ? 128 : 0) +
1252 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1261 struct inflate_state FAR *state;
1262 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1264 state = (struct inflate_state FAR *)strm->state;
1265 if (state->window != Z_NULL) ZFREE(strm, state->window);
1266 ZFREE(strm, strm->state);
1267 strm->state = Z_NULL;
1277 struct inflate_state FAR *state;
1283 /* check state */
1284 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1285 state = (struct inflate_state FAR *)strm->state;
1286 if (state->wrap != 0 && state->mode != DICT)
1290 if (state->mode == DICT) {
1293 if (id != state->check)
1307 state->mode = MEM;
1310 state->havedict = 1;
1319 struct inflate_state FAR *state;
1321 /* check state */
1322 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1323 state = (struct inflate_state FAR *)strm->state;
1324 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1327 state->head = head;
1336 state. If on return *have equals four, then the pattern was found and the
1340 called again with more data and the *have state. *have is initialized to
1372 struct inflate_state FAR *state;
1375 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1376 state = (struct inflate_state FAR *)strm->state;
1377 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1380 if (state->mode != SYNC) {
1381 state->mode = SYNC;
1382 state->hold <<= state->bits & 7;
1383 state->bits -= state->bits & 7;
1385 while (state->bits >= 8) {
1386 buf[len++] = (unsigned char)(state->hold);
1387 state->hold >>= 8;
1388 state->bits -= 8;
1390 state->have = 0;
1391 syncsearch(&(state->have), buf, len);
1395 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1401 if (state->have != 4) return Z_DATA_ERROR;
1405 state->mode = TYPE;
1420 struct inflate_state FAR *state;
1422 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1423 state = (struct inflate_state FAR *)strm->state;
1424 return state->mode == STORED && state->bits == 0;
1431 struct inflate_state FAR *state;
1437 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1440 state = (struct inflate_state FAR *)source->state;
1447 if (state->window != Z_NULL) {
1449 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1456 /* copy state */
1458 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1459 if (state->lencode >= state->codes &&
1460 state->lencode <= state->codes + ENOUGH - 1) {
1461 copy->lencode = copy->codes + (state->lencode - state->codes);
1462 copy->distcode = copy->codes + (state->distcode - state->codes);
1464 copy->next = copy->codes + (state->next - state->codes);
1466 wsize = 1U << state->wbits;
1467 zmemcpy(window, state->window, wsize);
1470 dest->state = (struct internal_state FAR *)copy;
1478 struct inflate_state FAR *state;
1480 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1481 state = (struct inflate_state FAR *)strm->state;
1482 state->sane = !subvert;
1486 state->sane = 1;
1494 struct inflate_state FAR *state;
1496 if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1497 state = (struct inflate_state FAR *)strm->state;
1498 return ((long)(state->back) << 16) +
1499 (state->mode == COPY ? state->length :
1500 (state->mode == MATCH ? state->was - state->length : 0));