Home | History | Annotate | Download | only in zlib

Lines Matching refs:state

28  * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
32 * - Add comments on state->bits assertion in inffast.c
97 struct inflate_state FAR *state;
101 state = (struct inflate_state FAR *)strm->state;
102 if (state == Z_NULL || state->strm != strm ||
103 state->mode < HEAD || state->mode > SYNC)
109 struct inflate_state FAR *state;
112 state = (struct inflate_state FAR *)strm->state;
113 strm->total_in = strm->total_out = state->total = 0;
115 if (state->wrap) /* to support ill-conceived Java test suite */
116 strm->adler = state->wrap & 1;
117 state->mode = HEAD;
118 state->last = 0;
119 state->havedict = 0;
120 state->flags = -1;
121 state->dmax = 32768U;
122 state->head = Z_NULL;
123 state->hold = 0;
124 state->bits = 0;
125 state->lencode = state->distcode = state->next = state->codes;
126 state->sane = 1;
127 state->back = -1;
133 struct inflate_state FAR *state;
136 state = (struct inflate_state FAR *)strm->state;
137 state->wsize = 0;
138 state->whave = 0;
139 state->wnext = 0;
145 struct inflate_state FAR *state;
147 /* get the state */
149 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;
183 struct inflate_state FAR *state;
204 state = (struct inflate_state FAR *)
206 if (state == Z_NULL) return Z_MEM_ERROR;
208 strm->state = (struct internal_state FAR *)state;
209 state->strm = strm;
210 state->window = Z_NULL;
211 state->mode = HEAD; /* to pass state test in inflateReset2() */
214 ZFREE(strm, state);
215 strm->state = Z_NULL;
226 struct inflate_state FAR *state;
231 state = (struct inflate_state FAR *)strm->state;
233 state->hold = 0;
234 state->bits = 0;
237 if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
239 state->hold += (unsigned)value << state->bits;
240 state->bits += (uInt)bits;
245 Return state with length and distance decoding tables and index sizes set to
254 local void fixedtables(struct inflate_state FAR *state) {
267 while (sym < 144) state->lens[sym++] = 8;
268 while (sym < 256) state->lens[sym++] = 9;
269 while (sym < 280) state->lens[sym++] = 7;
270 while (sym < 288) state->lens[sym++] = 8;
274 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
278 while (sym < 32) state->lens[sym++] = 5;
281 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
289 state->lencode = lenfix;
290 state->lenbits = 9;
291 state->distcode = distfix;
292 state->distbits = 5;
319 struct inflate_state state;
321 fixedtables(&state);
336 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
337 state.lencode[low].bits, state.lencode[low].val);
347 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
348 state.distcode[low].val);
371 struct inflate_state FAR *state;
374 state = (struct inflate_state FAR *)strm->state;
377 if (state->window == Z_NULL) {
378 state->window = (unsigned char FAR *)
379 ZALLOC(strm, 1U << state->wbits,
381 if (state->window == Z_NULL) return 1;
385 if (state->wsize == 0) {
386 state->wsize = 1U << state->wbits;
387 state->wnext = 0;
388 state->whave = 0;
391 /* copy state->wsize or less output bytes into the circular window */
392 if (copy >= state->wsize) {
393 zmemcpy(state->window, end - state->wsize, state->wsize);
394 state->wnext = 0;
395 state->whave = state->wsize;
398 dist = state->wsize - state->wnext;
400 zmemcpy(state->window + state->wnext, end - copy, dist);
403 zmemcpy(state->window, end - copy, copy);
404 state->wnext = copy;
405 state->whave = state->wsize;
408 state->wnext += dist;
409 if (state->wnext == state->wsize) state->wnext = 0;
410 if (state->whave < state->wsize) state->whave += dist;
421 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
445 /* Load registers with state in inflate() for speed */
452 hold = state->hold; \
453 bits = state->bits; \
456 /* Restore state from registers in inflate() */
463 state->hold = hold; \
464 state->bits = bits; \
511 inflate() uses a state machine to process as much input data and generate as
512 much output data as possible before returning. The state machine is
515 for (;;) switch (state) {
521 state = STATEm;
528 next state. The NEEDBITS() macro is usually the way the state evaluates
551 state information is maintained to continue the loop where it left off
553 would all have to actually be part of the saved state in case NEEDBITS()
562 state = STATEx;
565 As shown above, if the next state is also the next case, then the break
568 A state may also return if there is not enough output space available to
569 complete that state. Those states are copying stored data, writing a
593 struct inflate_state FAR *state;
623 state = (struct inflate_state FAR *)strm->state;
624 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
630 switch (state->mode) {
632 if (state->wrap == 0) {
633 state->mode = TYPEDO;
638 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
639 if (state->wbits == 0)
640 state->wbits = 15;
641 state->check = crc32(0L, Z_NULL, 0);
642 CRC2(state->check, hold);
644 state->mode = FLAGS;
647 if (state->head != Z_NULL)
648 state->head->done = -1;
649 if (!(state->wrap & 1) || /* check if zlib header allowed */
655 state->mode = BAD;
660 state->mode = BAD;
665 if (state->wbits == 0)
666 state->wbits = len;
667 if (len > 15 || len > state->wbits) {
669 state->mode = BAD;
672 state->dmax = 1U << len;
673 state->flags = 0; /* indicate zlib header */
675 strm->adler = state->check = adler32(0L, Z_NULL, 0);
676 state->mode = hold & 0x200 ? DICTID : TYPE;
682 state->flags = (int)(hold);
683 if ((state->flags & 0xff) != Z_DEFLATED) {
685 state->mode = BAD;
688 if (state->flags & 0xe000) {
690 state->mode = BAD;
693 if (state->head != Z_NULL)
694 state->head->text = (int)((hold >> 8) & 1);
695 if ((state->flags & 0x0200) && (state->wrap & 4))
696 CRC2(state->check, hold);
698 state->mode = TIME;
702 if (state->head != Z_NULL)
703 state->head->time = hold;
704 if ((state->flags & 0x0200) && (state->wrap & 4))
705 CRC4(state->check, hold);
707 state->mode = OS;
711 if (state->head != Z_NULL) {
712 state->head->xflags = (int)(hold & 0xff);
713 state->head->os = (int)(hold >> 8);
715 if ((state->flags & 0x0200) && (state->wrap & 4))
716 CRC2(state->check, hold);
718 state->mode = EXLEN;
721 if (state->flags & 0x0400) {
723 state->length = (unsigned)(hold);
724 if (state->head != Z_NULL)
725 state->head->extra_len = (unsigned)hold;
726 if ((state->flags & 0x0200) && (state->wrap & 4))
727 CRC2(state->check, hold);
730 else if (state->head != Z_NULL)
731 state->head->extra = Z_NULL;
732 state->mode = EXTRA;
735 if (state->flags & 0x0400) {
736 copy = state->length;
739 if (state->head != Z_NULL &&
740 state->head->extra != Z_NULL &&
741 (len = state->head->extra_len - state->length) <
742 state->head->extra_max) {
743 zmemcpy(state->head->extra + len, next,
744 len + copy > state->head->extra_max ?
745 state->head->extra_max - len : copy);
747 if ((state->flags & 0x0200) && (state->wrap & 4))
748 state->check = crc32(state->check, next, copy);
751 state->length -= copy;
753 if (state->length) goto inf_leave;
755 state->length = 0;
756 state->mode = NAME;
759 if (state->flags & 0x0800) {
764 if (state->head != Z_NULL &&
765 state->head->name != Z_NULL &&
766 state->length < state->head->name_max)
767 state->head->name[state->length++] = (Bytef)len;
769 if ((state->flags & 0x0200) && (state->wrap & 4))
770 state->check = crc32(state->check, next, copy);
775 else if (state->head != Z_NULL)
776 state->head->name = Z_NULL;
777 state->length = 0;
778 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++] = (Bytef)len;
791 if ((state->flags & 0x0200) && (state->wrap & 4))
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;
802 if (state->flags & 0x0200) {
804 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
806 state->mode = BAD;
811 if (state->head != Z_NULL) {
812 state->head->hcrc = (int)((state->flags >> 9) & 1);
813 state->head->done = 1;
815 strm->adler = state->check = crc32(0L, Z_NULL, 0);
816 state->mode = TYPE;
821 strm->adler = state->check = ZSWAP32(hold);
823 state->mode = DICT;
826 if (state->havedict == 0) {
830 strm->adler = state->check = adler32(0L, Z_NULL, 0);
831 state->mode = TYPE;
837 if (state->last) {
839 state->mode = CHECK;
843 state->last = BITS(1);
848 state->last ? " (last)" : ""));
849 state->mode = STORED;
852 fixedtables(state);
854 state->last ? " (last)" : ""));
855 state->mode = LEN_; /* decode codes */
863 state->last ? " (last)" : ""));
864 state->mode = TABLE;
868 state->mode = BAD;
877 state->mode = BAD;
880 state->length = (unsigned)hold & 0xffff;
882 state->length));
884 state->mode = COPY_;
888 state->mode = COPY;
891 copy = state->length;
901 state->length -= copy;
905 state->mode = TYPE;
909 state->nlen = BITS(5) + 257;
911 state->ndist = BITS(5) + 1;
913 state->ncode = BITS(4) + 4;
916 if (state->nlen > 286 || state->ndist > 30) {
918 state->mode = BAD;
923 state->have = 0;
924 state->mode = LENLENS;
927 while (state->have < state->ncode) {
929 state->lens[order[state->have++]] = (unsigned short)BITS(3);
932 while (state->have < 19)
933 state->lens[order[state->have++]] = 0;
934 state->next = state->codes;
935 state->lencode = (const code FAR *)(state->next);
936 state->lenbits = 7;
937 ret = inflate_table(CODES, state->lens, 19, &(state->next),
938 &(state->lenbits), state->work);
941 state->mode = BAD;
945 state->have = 0;
946 state->mode = CODELENS;
949 while (state->have < state->nlen + state->ndist) {
951 here = state->lencode[BITS(state->lenbits)];
957 state->lens[state->have++] = here.val;
963 if (state->have == 0) {
965 state->mode = BAD;
968 len = state->lens[state->have - 1];
986 if (state->have + copy > state->nlen + state->ndist) {
988 state->mode = BAD;
992 state->lens[state->have++] = (unsigned short)len;
997 if (state->mode == BAD) break;
1000 if (state->lens[256] == 0) {
1002 state->mode = BAD;
1009 state->next = state->codes;
1010 state->lencode = (const code FAR *)(state->next);
1011 state->lenbits = 9;
1012 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1013 &(state->lenbits), state->work);
1016 state->mode = BAD;
1019 state->distcode = (const code FAR *)(state->next);
1020 state->distbits = 6;
1021 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1022 &(state->next), &(state->distbits), state->work);
1025 state->mode = BAD;
1029 state->mode = LEN_;
1033 state->mode = LEN;
1040 if (state->mode == TYPE)
1041 state->back = -1;
1044 state->back = 0;
1046 here = state->lencode[BITS(state->lenbits)];
1053 here = state->lencode[last.val +
1059 state->back += last.bits;
1062 state->back += here.bits;
1063 state->length = (unsigned)here.val;
1068 state->mode = LIT;
1073 state->back = -1;
1074 state->mode = TYPE;
1079 state->mode = BAD;
1082 state->extra = (unsigned)(here.op) & 15;
1083 state->mode = LENEXT;
1086 if (state->extra) {
1087 NEEDBITS(state->extra);
1088 state->length += BITS(state->extra);
1089 DROPBITS(state->extra);
1090 state->back += state->extra;
1092 Tracevv((stderr, "inflate: length %u\n", state->length));
1093 state->was = state->length;
1094 state->mode = DIST;
1098 here = state->distcode[BITS(state->distbits)];
1105 here = state->distcode[last.val +
1111 state->back += last.bits;
1114 state->back += here.bits;
1117 state->mode = BAD;
1120 state->offset = (unsigned)here.val;
1121 state->extra = (unsigned)(here.op) & 15;
1122 state->mode = DISTEXT;
1125 if (state->extra) {
1126 NEEDBITS(state->extra);
1127 state->offset += BITS(state->extra);
1128 DROPBITS(state->extra);
1129 state->back += state->extra;
1132 if (state->offset > state->dmax) {
1134 state->mode = BAD;
1138 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1139 state->mode = MATCH;
1144 if (state->offset > copy) { /* copy from window */
1145 copy = state->offset - copy;
1146 if (copy > state->whave) {
1147 if (state->sane) {
1149 state->mode = BAD;
1154 copy -= state->whave;
1155 if (copy > state->length) copy = state->length;
1158 state->length -= copy;
1162 if (state->length == 0) state->mode = LEN;
1166 if (copy > state->wnext) {
1167 copy -= state->wnext;
1168 from = state->window + (state->wsize - copy);
1171 from = state->window + (state->wnext - copy);
1172 if (copy > state->length) copy = state->length;
1175 from = put - state->offset;
1176 copy = state->length;
1180 state->length -= copy;
1184 if (state->length == 0) state->mode = LEN;
1188 *put++ = (unsigned char)(state->length);
1190 state->mode = LEN;
1193 if (state->wrap) {
1197 state->total += out;
1198 if ((state->wrap & 4) && out)
1199 strm->adler = state->check =
1200 UPDATE_CHECK(state->check, put - out, out);
1202 if ((state->wrap & 4) && (
1204 state->flags ? hold :
1206 ZSWAP32(hold)) != state->check) {
1208 state->mode = BAD;
1215 state->mode = LENGTH;
1218 if (state->wrap && state->flags) {
1220 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1222 state->mode = BAD;
1229 state->mode = DONE;
1248 error. Call updatewindow() to create and/or update the window state.
1253 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1254 (state->mode < CHECK || flush != Z_FINISH)))
1256 state->mode = MEM;
1263 state->total += out;
1264 if ((state->wrap & 4) && out)
1265 strm->adler = state->check =
1266 UPDATE_CHECK(state->check, strm->next_out - out, out);
1267 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1268 (state->mode == TYPE ? 128 : 0) +
1269 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1276 struct inflate_state FAR *state;
1279 state = (struct inflate_state FAR *)strm->state;
1280 if (state->window != Z_NULL) ZFREE(strm, state->window);
1281 ZFREE(strm, strm->state);
1282 strm->state = Z_NULL;
1289 struct inflate_state FAR *state;
1291 /* check state */
1293 state = (struct inflate_state FAR *)strm->state;
1296 if (state->whave && dictionary != Z_NULL) {
1297 zmemcpy(dictionary, state->window + state->wnext,
1298 state->whave - state->wnext);
1299 zmemcpy(dictionary + state->whave - state->wnext,
1300 state->window, state->wnext);
1303 *dictLength = state->whave;
1309 struct inflate_state FAR *state;
1313 /* check state */
1315 state = (struct inflate_state FAR *)strm->state;
1316 if (state->wrap != 0 && state->mode != DICT)
1320 if (state->mode == DICT) {
1323 if (dictid != state->check)
1331 state->mode = MEM;
1334 state->havedict = 1;
1340 struct inflate_state FAR *state;
1342 /* check state */
1344 state = (struct inflate_state FAR *)strm->state;
1345 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1348 state->head = head;
1357 state. If on return *have equals four, then the pattern was found and the
1361 called again with more data and the *have state. *have is initialized to
1389 struct inflate_state FAR *state;
1393 state = (struct inflate_state FAR *)strm->state;
1394 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1397 if (state->mode != SYNC) {
1398 state->mode = SYNC;
1399 state->hold >>= state->bits & 7;
1400 state->bits -= state->bits & 7;
1402 while (state->bits >= 8) {
1403 buf[len++] = (unsigned char)(state->hold);
1404 state->hold >>= 8;
1405 state->bits -= 8;
1407 state->have = 0;
1408 syncsearch(&(state->have), buf, len);
1412 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1418 if (state->have != 4) return Z_DATA_ERROR;
1419 if (state->flags == -1)
1420 state->wrap = 0; /* if no header yet, treat as raw */
1422 state->wrap &= ~4; /* no point in computing a check value now */
1423 flags = state->flags;
1427 state->flags = flags;
1428 state->mode = TYPE;
1441 struct inflate_state FAR *state;
1444 state = (struct inflate_state FAR *)strm->state;
1445 return state->mode == STORED && state->bits == 0;
1449 struct inflate_state FAR *state;
1457 state = (struct inflate_state FAR *)source->state;
1464 if (state->window != Z_NULL) {
1466 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1473 /* copy state */
1475 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1477 if (state->lencode >= state->codes &&
1478 state->lencode <= state->codes + ENOUGH - 1) {
1479 copy->lencode = copy->codes + (state->lencode - state->codes);
1480 copy->distcode = copy->codes + (state->distcode - state->codes);
1482 copy->next = copy->codes + (state->next - state->codes);
1484 wsize = 1U << state->wbits;
1485 zmemcpy(window, state->window, wsize);
1488 dest->state = (struct internal_state FAR *)copy;
1493 struct inflate_state FAR *state;
1496 state = (struct inflate_state FAR *)strm->state;
1498 state->sane = !subvert;
1502 state->sane = 1;
1508 struct inflate_state FAR *state;
1511 state = (struct inflate_state FAR *)strm->state;
1512 if (check && state->wrap)
1513 state->wrap |= 4;
1515 state->wrap &= ~4;
1520 struct inflate_state FAR *state;
1524 state = (struct inflate_state FAR *)strm->state;
1525 return (long)(((unsigned long)((long)state->back)) << 16) +
1526 (state->mode == COPY ? state->length :
1527 (state->mode == MATCH ? state->was - state->length : 0));
1531 struct inflate_state FAR *state;
1533 state = (struct inflate_state FAR *)strm->state;
1534 return (unsigned long)(state->next - state->codes);