Home | History | Annotate | Download | only in src

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));
107 struct inflate_state FAR *state;
109 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
110 state = (struct inflate_state FAR *)strm->state;
111 strm->total_in = strm->total_out = state->total = 0;
113 if (state->wrap) /* to support ill-conceived Java test suite */
114 strm->adler = state->wrap & 1;
115 state->mode = HEAD;
116 state->last = 0;
117 state->havedict = 0;
118 state->dmax = 32768U;
119 state->head = Z_NULL;
120 state->hold = 0;
121 state->bits = 0;
122 state->lencode = state->distcode = state->next = state->codes;
123 state->sane = 1;
124 state->back = -1;
132 struct inflate_state FAR *state;
134 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
135 state = (struct inflate_state FAR *)strm->state;
136 state->wsize = 0;
137 state->whave = 0;
138 state->wnext = 0;
147 struct inflate_state FAR *state;
149 /* get the state */
150 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
151 state = (struct inflate_state FAR *)strm->state;
169 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
170 ZFREE(strm, state->window);
171 state->window = Z_NULL;
174 /* update state and reset the rest of it */
175 state->wrap = wrap;
176 state->wbits = (unsigned)windowBits;
187 struct inflate_state FAR *state;
208 state = (struct inflate_state FAR *)
210 if (state == Z_NULL) return Z_MEM_ERROR;
212 strm->state = (struct internal_state FAR *)state;
213 state->window = Z_NULL;
216 ZFREE(strm, state);
217 strm->state = Z_NULL;
235 struct inflate_state FAR *state;
237 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
238 state = (struct inflate_state FAR *)strm->state;
240 state->hold = 0;
241 state->bits = 0;
244 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
246 state->hold += value << state->bits;
247 state->bits += bits;
252 Return state with length and distance decoding tables and index sizes set to
261 local void fixedtables(state)
262 struct inflate_state FAR *state;
276 while (sym < 144) state->lens[sym++] = 8;
277 while (sym < 256) state->lens[sym++] = 9;
278 while (sym < 280) state->lens[sym++] = 7;
279 while (sym < 288) state->lens[sym++] = 8;
283 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
287 while (sym < 32) state->lens[sym++] = 5;
290 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
298 state->lencode = lenfix;
299 state->lenbits = 9;
300 state->distcode = distfix;
301 state->distbits = 5;
328 struct inflate_state state;
330 fixedtables(&state);
345 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
346 state.lencode[low].bits, state.lencode[low].val);
356 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
357 state.distcode[low].val);
384 struct inflate_state FAR *state;
387 state = (struct inflate_state FAR *)strm->state;
390 if (state->window == Z_NULL) {
391 state->window = (unsigned char FAR *)
392 ZALLOC(strm, 1U << state->wbits,
394 if (state->window == Z_NULL) return 1;
398 if (state->wsize == 0) {
399 state->wsize = 1U << state->wbits;
400 state->wnext = 0;
401 state->whave = 0;
404 /* copy state->wsize or less output bytes into the circular window */
405 if (copy >= state->wsize) {
406 zmemcpy(state->window, end - state->wsize, state->wsize);
407 state->wnext = 0;
408 state->whave = state->wsize;
411 dist = state->wsize - state->wnext;
413 zmemcpy(state->window + state->wnext, end - copy, dist);
416 zmemcpy(state->window, end - copy, copy);
417 state->wnext = copy;
418 state->whave = state->wsize;
421 state->wnext += dist;
422 if (state->wnext == state->wsize) state->wnext = 0;
423 if (state->whave < state->wsize) state->whave += dist;
434 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
458 /* Load registers with state in inflate() for speed */
465 hold = state->hold; \
466 bits = state->bits; \
469 /* Restore state from registers in inflate() */
476 state->hold = hold; \
477 state->bits = bits; \
524 inflate() uses a state machine to process as much input data and generate as
525 much output data as possible before returning. The state machine is
528 for (;;) switch (state) {
534 state = STATEm;
541 next state. The NEEDBITS() macro is usually the way the state evaluates
564 state information is maintained to continue the loop where it left off
566 would all have to actually be part of the saved state in case NEEDBITS()
575 state = STATEx;
578 As shown above, if the next state is also the next case, then the break
581 A state may also return if there is not enough output space available to
582 complete that state. Those states are copying stored data, writing a
609 struct inflate_state FAR *state;
628 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
632 state = (struct inflate_state FAR *)strm->state;
633 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
639 switch (state->mode) {
641 if (state->wrap == 0) {
642 state->mode = TYPEDO;
647 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
648 state->check = crc32(0L, Z_NULL, 0);
649 CRC2(state->check, hold);
651 state->mode = FLAGS;
654 state->flags = 0; /* expect zlib header */
655 if (state->head != Z_NULL)
656 state->head->done = -1;
657 if (!(state->wrap & 1) || /* check if zlib header allowed */
663 state->mode = BAD;
668 state->mode = BAD;
673 if (state->wbits == 0)
674 state->wbits = len;
675 else if (len > state->wbits) {
677 state->mode = BAD;
680 state->dmax = 1U << len;
682 strm->adler = state->check = adler32(0L, Z_NULL, 0);
683 state->mode = hold & 0x200 ? DICTID : TYPE;
689 state->flags = (int)(hold);
690 if ((state->flags & 0xff) != Z_DEFLATED) {
692 state->mode = BAD;
695 if (state->flags & 0xe000) {
697 state->mode = BAD;
700 if (state->head != Z_NULL)
701 state->head->text = (int)((hold >> 8) & 1);
702 if (state->flags & 0x0200) CRC2(state->check, hold);
704 state->mode = TIME;
707 if (state->head != Z_NULL)
708 state->head->time = hold;
709 if (state->flags & 0x0200) CRC4(state->check, hold);
711 state->mode = OS;
714 if (state->head != Z_NULL) {
715 state->head->xflags = (int)(hold & 0xff);
716 state->head->os = (int)(hold >> 8);
718 if (state->flags & 0x0200) CRC2(state->check, hold);
720 state->mode = EXLEN;
722 if (state->flags & 0x0400) {
724 state->length = (unsigned)(hold);
725 if (state->head != Z_NULL)
726 state->head->extra_len = (unsigned)hold;
727 if (state->flags & 0x0200) CRC2(state->check, hold);
730 else if (state->head != Z_NULL)
731 state->head->extra = Z_NULL;
732 state->mode = EXTRA;
734 if (state->flags & 0x0400) {
735 copy = state->length;
738 if (state->head != Z_NULL &&
739 state->head->extra != Z_NULL) {
740 len = state->head->extra_len - state->length;
741 zmemcpy(state->head->extra + len, next,
742 len + copy > state->head->extra_max ?
743 state->head->extra_max - len : copy);
745 if (state->flags & 0x0200)
746 state->check = crc32(state->check, next, copy);
749 state->length -= copy;
751 if (state->length) goto inf_leave;
753 state->length = 0;
754 state->mode = NAME;
756 if (state->flags & 0x0800) {
761 if (state->head != Z_NULL &&
762 state->head->name != Z_NULL &&
763 state->length < state->head->name_max)
764 state->head->name[state->length++] = len;
766 if (state->flags & 0x0200)
767 state->check = crc32(state->check, next, copy);
772 else if (state->head != Z_NULL)
773 state->head->name = Z_NULL;
774 state->length = 0;
775 state->mode = COMMENT;
777 if (state->flags & 0x1000) {
782 if (state->head != Z_NULL &&
783 state->head->comment != Z_NULL &&
784 state->length < state->head->comm_max)
785 state->head->comment[state->length++] = len;
787 if (state->flags & 0x0200)
788 state->check = crc32(state->check, next, copy);
793 else if (state->head != Z_NULL)
794 state->head->comment = Z_NULL;
795 state->mode = HCRC;
797 if (state->flags & 0x0200) {
799 if (hold != (state->check & 0xffff)) {
801 state->mode = BAD;
806 if (state->head != Z_NULL) {
807 state->head->hcrc = (int)((state->flags >> 9) & 1);
808 state->head->done = 1;
810 strm->adler = state->check = crc32(0L, Z_NULL, 0);
811 state->mode = TYPE;
816 strm->adler = state->check = ZSWAP32(hold);
818 state->mode = DICT;
820 if (state->havedict == 0) {
824 strm->adler = state->check = adler32(0L, Z_NULL, 0);
825 state->mode = TYPE;
829 if (state->last) {
831 state->mode = CHECK;
835 state->last = BITS(1);
840 state->last ? " (last)" : ""));
841 state->mode = STORED;
844 fixedtables(state);
846 state->last ? " (last)" : ""));
847 state->mode = LEN_; /* decode codes */
855 state->last ? " (last)" : ""));
856 state->mode = TABLE;
860 state->mode = BAD;
869 state->mode = BAD;
872 state->length = (unsigned)hold & 0xffff;
874 state->length));
876 state->mode = COPY_;
879 state->mode = COPY;
881 copy = state->length;
891 state->length -= copy;
895 state->mode = TYPE;
899 state->nlen = BITS(5) + 257;
901 state->ndist = BITS(5) + 1;
903 state->ncode = BITS(4) + 4;
906 if (state->nlen > 286 || state->ndist > 30) {
908 state->mode = BAD;
913 state->have = 0;
914 state->mode = LENLENS;
916 while (state->have < state->ncode) {
918 state->lens[order[state->have++]] = (unsigned short)BITS(3);
921 while (state->have < 19)
922 state->lens[order[state->have++]] = 0;
923 state->next = state->codes;
924 state->lencode = (const code FAR *)(state->next);
925 state->lenbits = 7;
926 ret = inflate_table(CODES, state->lens, 19, &(state->next),
927 &(state->lenbits), state->work);
930 state->mode = BAD;
934 state->have = 0;
935 state->mode = CODELENS;
937 while (state->have < state->nlen + state->ndist) {
939 here = state->lencode[BITS(state->lenbits)];
945 state->lens[state->have++] = here.val;
951 if (state->have == 0) {
953 state->mode = BAD;
956 len = state->lens[state->have - 1];
974 if (state->have + copy > state->nlen + state->ndist) {
976 state->mode = BAD;
980 state->lens[state->have++] = (unsigned short)len;
985 if (state->mode == BAD) break;
988 if (state->lens[256] == 0) {
990 state->mode = BAD;
997 state->next = state->codes;
998 state->lencode = (const code FAR *)(state->next);
999 state->lenbits = 9;
1000 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1001 &(state->lenbits), state->work);
1004 state->mode = BAD;
1007 state->distcode = (const code FAR *)(state->next);
1008 state->distbits = 6;
1009 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1010 &(state->next), &(state->distbits), state->work);
1013 state->mode = BAD;
1017 state->mode = LEN_;
1020 state->mode = LEN;
1026 if (state->mode == TYPE)
1027 state->back = -1;
1030 state->back = 0;
1032 here = state->lencode[BITS(state->lenbits)];
1039 here = state->lencode[last.val +
1045 state->back += last.bits;
1048 state->back += here.bits;
1049 state->length = (unsigned)here.val;
1054 state->mode = LIT;
1059 state->back = -1;
1060 state->mode = TYPE;
1065 state->mode = BAD;
1068 state->extra = (unsigned)(here.op) & 15;
1069 state->mode = LENEXT;
1071 if (state->extra) {
1072 NEEDBITS(state->extra);
1073 state->length += BITS(state->extra);
1074 DROPBITS(state->extra);
1075 state->back += state->extra;
1077 Tracevv((stderr, "inflate: length %u\n", state->length));
1078 state->was = state->length;
1079 state->mode = DIST;
1082 here = state->distcode[BITS(state->distbits)];
1089 here = state->distcode[last.val +
1095 state->back += last.bits;
1098 state->back += here.bits;
1101 state->mode = BAD;
1104 state->offset = (unsigned)here.val;
1105 state->extra = (unsigned)(here.op) & 15;
1106 state->mode = DISTEXT;
1108 if (state->extra) {
1109 NEEDBITS(state->extra);
1110 state->offset += BITS(state->extra);
1111 DROPBITS(state->extra);
1112 state->back += state->extra;
1115 if (state->offset > state->dmax) {
1117 state->mode = BAD;
1121 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1122 state->mode = MATCH;
1126 if (state->offset > copy) { /* copy from window */
1127 copy = state->offset - copy;
1128 if (copy > state->whave) {
1129 if (state->sane) {
1131 state->mode = BAD;
1136 copy -= state->whave;
1137 if (copy > state->length) copy = state->length;
1140 state->length -= copy;
1144 if (state->length == 0) state->mode = LEN;
1148 if (copy > state->wnext) {
1149 copy -= state->wnext;
1150 from = state->window + (state->wsize - copy);
1153 from = state->window + (state->wnext - copy);
1154 if (copy > state->length) copy = state->length;
1157 from = put - state->offset;
1158 copy = state->length;
1162 state->length -= copy;
1166 if (state->length == 0) state->mode = LEN;
1170 *put++ = (unsigned char)(state->length);
1172 state->mode = LEN;
1175 if (state->wrap) {
1179 state->total += out;
1181 strm->adler = state->check =
1182 UPDATE(state->check, put - out, out);
1186 state->flags ? hold :
1188 ZSWAP32(hold)) != state->check) {
1190 state->mode = BAD;
1197 state->mode = LENGTH;
1199 if (state->wrap && state->flags) {
1201 if (hold != (state->total & 0xffffffffUL)) {
1203 state->mode = BAD;
1210 state->mode = DONE;
1227 error. Call updatewindow() to create and/or update the window state.
1232 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1233 (state->mode < CHECK || flush != Z_FINISH)))
1235 state->mode = MEM;
1242 state->total += out;
1243 if (state->wrap && out)
1244 strm->adler = state->check =
1245 UPDATE(state->check, strm->next_out - out, out);
1246 strm->data_type = state->bits + (state->last ? 64 : 0) +
1247 (state->mode == TYPE ? 128 : 0) +
1248 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1257 struct inflate_state FAR *state;
1258 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1260 state = (struct inflate_state FAR *)strm->state;
1261 if (state->window != Z_NULL) ZFREE(strm, state->window);
1262 ZFREE(strm, strm->state);
1263 strm->state = Z_NULL;
1273 struct inflate_state FAR *state;
1275 /* check state */
1276 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1277 state = (struct inflate_state FAR *)strm->state;
1280 if (state->whave && dictionary != Z_NULL) {
1281 zmemcpy(dictionary, state->window + state->wnext,
1282 state->whave - state->wnext);
1283 zmemcpy(dictionary + state->whave - state->wnext,
1284 state->window, state->wnext);
1287 *dictLength = state->whave;
1296 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 != 0 && state->mode != DICT)
1307 if (state->mode == DICT) {
1310 if (dictid != state->check)
1318 state->mode = MEM;
1321 state->havedict = 1;
1330 struct inflate_state FAR *state;
1332 /* check state */
1333 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1334 state = (struct inflate_state FAR *)strm->state;
1335 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1338 state->head = head;
1347 state. If on return *have equals four, then the pattern was found and the
1351 called again with more data and the *have state. *have is initialized to
1383 struct inflate_state FAR *state;
1386 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1387 state = (struct inflate_state FAR *)strm->state;
1388 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1391 if (state->mode != SYNC) {
1392 state->mode = SYNC;
1393 state->hold <<= state->bits & 7;
1394 state->bits -= state->bits & 7;
1396 while (state->bits >= 8) {
1397 buf[len++] = (unsigned char)(state->hold);
1398 state->hold >>= 8;
1399 state->bits -= 8;
1401 state->have = 0;
1402 syncsearch(&(state->have), buf, len);
1406 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1412 if (state->have != 4) return Z_DATA_ERROR;
1416 state->mode = TYPE;
1431 struct inflate_state FAR *state;
1433 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1434 state = (struct inflate_state FAR *)strm->state;
1435 return state->mode == STORED && state->bits == 0;
1442 struct inflate_state FAR *state;
1448 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1451 state = (struct inflate_state FAR *)source->state;
1458 if (state->window != Z_NULL) {
1460 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1467 /* copy state */
1469 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1470 if (state->lencode >= state->codes &&
1471 state->lencode <= state->codes + ENOUGH - 1) {
1472 copy->lencode = copy->codes + (state->lencode - state->codes);
1473 copy->distcode = copy->codes + (state->distcode - state->codes);
1475 copy->next = copy->codes + (state->next - state->codes);
1477 wsize = 1U << state->wbits;
1478 zmemcpy(window, state->window, wsize);
1481 dest->state = (struct internal_state FAR *)copy;
1489 struct inflate_state FAR *state;
1491 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1492 state = (struct inflate_state FAR *)strm->state;
1493 state->sane = !subvert;
1497 state->sane = 1;
1505 struct inflate_state FAR *state;
1507 if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1508 state = (struct inflate_state FAR *)strm->state;
1509 return ((long)(state->back) << 16) +
1510 (state->mode == COPY ? state->length :
1511 (state->mode == MATCH ? state->was - state->length : 0));