summaryrefslogtreecommitdiffstats
path: root/lib/libz/infblock.c
diff options
context:
space:
mode:
authorsteve <steve@FreeBSD.org>1998-02-28 06:04:26 +0000
committersteve <steve@FreeBSD.org>1998-02-28 06:04:26 +0000
commit9f86c0bf8cf1224d46bbefe1d308f2cc8186a79b (patch)
treef03de58d136ec48f008735e374079754bdfee40f /lib/libz/infblock.c
parent5372e3085661ee9071da924c16a5cfdc12f7590d (diff)
downloadFreeBSD-src-9f86c0bf8cf1224d46bbefe1d308f2cc8186a79b.zip
FreeBSD-src-9f86c0bf8cf1224d46bbefe1d308f2cc8186a79b.tar.gz
Initial import of zlib-1.1.1
PR: 5869 Reviewed by: jdp
Diffstat (limited to 'lib/libz/infblock.c')
-rw-r--r--lib/libz/infblock.c78
1 files changed, 37 insertions, 41 deletions
diff --git a/lib/libz/infblock.c b/lib/libz/infblock.c
index 89602a6..17943ab 100644
--- a/lib/libz/infblock.c
+++ b/lib/libz/infblock.c
@@ -1,5 +1,5 @@
/* infblock.c -- interpret and process block types to last block
- * Copyright (C) 1995-1996 Mark Adler
+ * Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -66,23 +66,19 @@ inflate_blocks_statef *s;
z_streamp z;
uLongf *c;
{
- if (s->checkfn != Z_NULL)
+ if (c != Z_NULL)
*c = s->check;
if (s->mode == BTREE || s->mode == DTREE)
ZFREE(z, s->sub.trees.blens);
if (s->mode == CODES)
- {
inflate_codes_free(s->sub.decode.codes, z);
- inflate_trees_free(s->sub.decode.td, z);
- inflate_trees_free(s->sub.decode.tl, z);
- }
s->mode = TYPE;
s->bitk = 0;
s->bitb = 0;
s->read = s->write = s->window;
if (s->checkfn != Z_NULL)
- z->adler = s->check = (*s->checkfn)(0L, Z_NULL, 0);
- Trace((stderr, "inflate: blocks reset\n"));
+ z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
+ Tracev((stderr, "inflate: blocks reset\n"));
}
@@ -96,23 +92,27 @@ uInt w;
if ((s = (inflate_blocks_statef *)ZALLOC
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
return s;
+ if ((s->hufts =
+ (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
+ {
+ ZFREE(z, s);
+ return Z_NULL;
+ }
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
{
+ ZFREE(z, s->hufts);
ZFREE(z, s);
return Z_NULL;
}
s->end = s->window + w;
s->checkfn = c;
s->mode = TYPE;
- Trace((stderr, "inflate: blocks allocated\n"));
- inflate_blocks_reset(s, z, &s->check);
+ Tracev((stderr, "inflate: blocks allocated\n"));
+ inflate_blocks_reset(s, z, Z_NULL);
return s;
}
-#ifdef DEBUG
- extern uInt inflate_hufts;
-#endif
int inflate_blocks(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
@@ -139,7 +139,7 @@ int r;
switch (t >> 1)
{
case 0: /* stored */
- Trace((stderr, "inflate: stored block%s\n",
+ Tracev((stderr, "inflate: stored block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
t = k & 7; /* go to byte boundary */
@@ -147,27 +147,25 @@ int r;
s->mode = LENS; /* get length of stored block */
break;
case 1: /* fixed */
- Trace((stderr, "inflate: fixed codes block%s\n",
+ Tracev((stderr, "inflate: fixed codes block%s\n",
s->last ? " (last)" : ""));
{
uInt bl, bd;
inflate_huft *tl, *td;
- inflate_trees_fixed(&bl, &bd, &tl, &td);
+ inflate_trees_fixed(&bl, &bd, &tl, &td, z);
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
if (s->sub.decode.codes == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
- s->sub.decode.tl = Z_NULL; /* don't try to free these */
- s->sub.decode.td = Z_NULL;
}
DUMPBITS(3)
s->mode = CODES;
break;
case 2: /* dynamic */
- Trace((stderr, "inflate: dynamic codes block%s\n",
+ Tracev((stderr, "inflate: dynamic codes block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
s->mode = TABLE;
@@ -224,8 +222,6 @@ int r;
}
#endif
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
- if (t < 19)
- t = 19;
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
{
r = Z_MEM_ERROR;
@@ -246,7 +242,7 @@ int r;
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.bb = 7;
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
- &s->sub.trees.tb, z);
+ &s->sub.trees.tb, s->hufts, z);
if (t != Z_OK)
{
ZFREE(z, s->sub.trees.blens);
@@ -288,7 +284,6 @@ int r;
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
(c == 16 && i < 1))
{
- inflate_trees_free(s->sub.trees.tb, z);
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
z->msg = (char*)"invalid bit length repeat";
@@ -302,7 +297,6 @@ int r;
s->sub.trees.index = i;
}
}
- inflate_trees_free(s->sub.trees.tb, z);
s->sub.trees.tb = Z_NULL;
{
uInt bl, bd;
@@ -312,11 +306,9 @@ int r;
bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table;
-#ifdef DEBUG
- inflate_hufts = 0;
-#endif
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
- s->sub.trees.blens, &bl, &bd, &tl, &td, z);
+ s->sub.trees.blens, &bl, &bd, &tl, &td,
+ s->hufts, z);
ZFREE(z, s->sub.trees.blens);
if (t != Z_OK)
{
@@ -325,18 +317,13 @@ int r;
r = t;
LEAVE
}
- Tracev((stderr, "inflate: trees ok, %d * %d bytes used\n",
- inflate_hufts, sizeof(inflate_huft)));
+ Tracev((stderr, "inflate: trees ok\n"));
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
{
- inflate_trees_free(td, z);
- inflate_trees_free(tl, z);
r = Z_MEM_ERROR;
LEAVE
}
s->sub.decode.codes = c;
- s->sub.decode.tl = tl;
- s->sub.decode.td = td;
}
s->mode = CODES;
case CODES:
@@ -345,8 +332,6 @@ int r;
return inflate_flush(s, z, r);
r = Z_OK;
inflate_codes_free(s->sub.decode.codes, z);
- inflate_trees_free(s->sub.decode.td, z);
- inflate_trees_free(s->sub.decode.tl, z);
LOAD
Tracev((stderr, "inflate: codes end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
@@ -382,15 +367,15 @@ int r;
}
-int inflate_blocks_free(s, z, c)
+int inflate_blocks_free(s, z)
inflate_blocks_statef *s;
z_streamp z;
-uLongf *c;
{
- inflate_blocks_reset(s, z, c);
+ inflate_blocks_reset(s, z, Z_NULL);
ZFREE(z, s->window);
+ ZFREE(z, s->hufts);
ZFREE(z, s);
- Trace((stderr, "inflate: blocks freed\n"));
+ Tracev((stderr, "inflate: blocks freed\n"));
return Z_OK;
}
@@ -400,6 +385,17 @@ inflate_blocks_statef *s;
const Bytef *d;
uInt n;
{
- zmemcpy((charf *)s->window, d, n);
+ zmemcpy(s->window, d, n);
s->read = s->write = s->window + n;
}
+
+
+/* Returns true if inflate is currently at the end of a block generated
+ * by Z_SYNC_FLUSH or Z_FULL_FLUSH.
+ * IN assertion: s != Z_NULL
+ */
+int inflate_blocks_sync_point(s)
+inflate_blocks_statef *s;
+{
+ return s->mode == LENS;
+}
OpenPOWER on IntegriCloud