Deleted Added
full compact
inflate.c (230837) inflate.c (237248)
1/* inflate.c -- zlib decompression
1/* inflate.c -- zlib decompression
2 * Copyright (C) 1995-2011 Mark Adler
2 * Copyright (C) 1995-2012 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * Change history:
8 *
9 * 1.2.beta0 24 Nov 2002
10 * - First version -- complete rewrite of inflate to simplify code, avoid

--- 503 unchanged lines hidden (view full) ---

514
515/* Remove zero to seven bits as needed to go to a byte boundary */
516#define BYTEBITS() \
517 do { \
518 hold >>= bits & 7; \
519 bits -= bits & 7; \
520 } while (0)
521
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * Change history:
8 *
9 * 1.2.beta0 24 Nov 2002
10 * - First version -- complete rewrite of inflate to simplify code, avoid

--- 503 unchanged lines hidden (view full) ---

514
515/* Remove zero to seven bits as needed to go to a byte boundary */
516#define BYTEBITS() \
517 do { \
518 hold >>= bits & 7; \
519 bits -= bits & 7; \
520 } while (0)
521
522/* Reverse the bytes in a 32-bit value */
523#define REVERSE(q) \
524 ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
525 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
526
527/*
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
530 structured roughly as follows:
531
532 for (;;) switch (state) {
533 ...
534 case STATEn:

--- 277 unchanged lines hidden (view full) ---

812 state->head->done = 1;
813 }
814 strm->adler = state->check = crc32(0L, Z_NULL, 0);
815 state->mode = TYPE;
816 break;
817#endif
818 case DICTID:
819 NEEDBITS(32);
522/*
523 inflate() uses a state machine to process as much input data and generate as
524 much output data as possible before returning. The state machine is
525 structured roughly as follows:
526
527 for (;;) switch (state) {
528 ...
529 case STATEn:

--- 277 unchanged lines hidden (view full) ---

807 state->head->done = 1;
808 }
809 strm->adler = state->check = crc32(0L, Z_NULL, 0);
810 state->mode = TYPE;
811 break;
812#endif
813 case DICTID:
814 NEEDBITS(32);
820 strm->adler = state->check = REVERSE(hold);
815 strm->adler = state->check = ZSWAP32(hold);
821 INITBITS();
822 state->mode = DICT;
823 case DICT:
824 if (state->havedict == 0) {
825 RESTORE();
826 return Z_NEED_DICT;
827 }
828 strm->adler = state->check = adler32(0L, Z_NULL, 0);

--- 355 unchanged lines hidden (view full) ---

1184 if (out)
1185 strm->adler = state->check =
1186 UPDATE(state->check, put - out, out);
1187 out = left;
1188 if ((
1189#ifdef GUNZIP
1190 state->flags ? hold :
1191#endif
816 INITBITS();
817 state->mode = DICT;
818 case DICT:
819 if (state->havedict == 0) {
820 RESTORE();
821 return Z_NEED_DICT;
822 }
823 strm->adler = state->check = adler32(0L, Z_NULL, 0);

--- 355 unchanged lines hidden (view full) ---

1179 if (out)
1180 strm->adler = state->check =
1181 UPDATE(state->check, put - out, out);
1182 out = left;
1183 if ((
1184#ifdef GUNZIP
1185 state->flags ? hold :
1186#endif
1192 REVERSE(hold)) != state->check) {
1187 ZSWAP32(hold)) != state->check) {
1193 strm->msg = (char *)"incorrect data check";
1194 state->mode = BAD;
1195 break;
1196 }
1197 INITBITS();
1198 Tracev((stderr, "inflate: check matches trailer\n"));
1199 }
1200#ifdef GUNZIP

--- 69 unchanged lines hidden (view full) ---

1270}
1271
1272int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
1273z_streamp strm;
1274const Bytef *dictionary;
1275uInt dictLength;
1276{
1277 struct inflate_state FAR *state;
1188 strm->msg = (char *)"incorrect data check";
1189 state->mode = BAD;
1190 break;
1191 }
1192 INITBITS();
1193 Tracev((stderr, "inflate: check matches trailer\n"));
1194 }
1195#ifdef GUNZIP

--- 69 unchanged lines hidden (view full) ---

1265}
1266
1267int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
1268z_streamp strm;
1269const Bytef *dictionary;
1270uInt dictLength;
1271{
1272 struct inflate_state FAR *state;
1278 unsigned long id;
1273 unsigned long dictid;
1279 unsigned char *next;
1280 unsigned avail;
1281 int ret;
1282
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)
1287 return Z_STREAM_ERROR;
1288
1274 unsigned char *next;
1275 unsigned avail;
1276 int ret;
1277
1278 /* check state */
1279 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1280 state = (struct inflate_state FAR *)strm->state;
1281 if (state->wrap != 0 && state->mode != DICT)
1282 return Z_STREAM_ERROR;
1283
1289 /* check for correct dictionary id */
1284 /* check for correct dictionary identifier */
1290 if (state->mode == DICT) {
1285 if (state->mode == DICT) {
1291 id = adler32(0L, Z_NULL, 0);
1292 id = adler32(id, dictionary, dictLength);
1293 if (id != state->check)
1286 dictid = adler32(0L, Z_NULL, 0);
1287 dictid = adler32(dictid, dictionary, dictLength);
1288 if (dictid != state->check)
1294 return Z_DATA_ERROR;
1295 }
1296
1297 /* copy dictionary to window using updatewindow(), which will amend the
1298 existing dictionary if appropriate */
1299 next = strm->next_out;
1300 avail = strm->avail_out;
1301 strm->next_out = (Bytef *)dictionary + dictLength;

--- 200 unchanged lines hidden ---
1289 return Z_DATA_ERROR;
1290 }
1291
1292 /* copy dictionary to window using updatewindow(), which will amend the
1293 existing dictionary if appropriate */
1294 next = strm->next_out;
1295 avail = strm->avail_out;
1296 strm->next_out = (Bytef *)dictionary + dictLength;

--- 200 unchanged lines hidden ---