flate

deflate implementation
git clone git://git.suckless.org/flate
Log | Files | Refs | README

commit 53eb52863fb946f8f15513663c16488de66ca003
parent 2ae4e90eab48bbaeaf4d2e5293569cde0758a9fc
Author: nsz@tpx <unknown>
Date:   Sun,  8 Aug 2010 16:28:50 +0200

fix deflate bug (match beyond endpos)
Diffstat:
deflate.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/deflate.c b/deflate.c @@ -327,7 +327,7 @@ static void deflate_block(State *s) { uchar *p; int dynsize, fixsize, uncsize; int blocklen = s->pos - s->startpos; - int dyntree; +/* int dyntree; */ /* calc dynamic codes */ hufflens(llen, s->lfreq, Nlitlen, CodeBits-1); @@ -358,7 +358,7 @@ static void deflate_block(State *s) { if (c == 18) dynsize += 7; } - dyntree = dynsize - 3; +/* dyntree = dynsize - 3; */ for (lz = s->lzbuf, p = s->src + s->startpos; lz != s->lz; lz++) if (lz->bits & LzLitFlag) for (n = lz->n; n > 0; n--, p++) { @@ -519,12 +519,12 @@ static Match getmatch(State *s, int next) { if (len > m.len) { m.dist = s->pos - next; m.len = len; - if (len == MaxMatch) - return m; if (s->pos + len >= s->endpos) { /* TODO: overflow */ m.len = s->endpos - s->pos; return m; } + if (len == MaxMatch) + return m; } } while ((next = s->chain[next % WinSize]) > limit && --chainlen); if (m.len < MinMatch || (m.len == MinMatch && m.dist > BigDist)) @@ -617,10 +617,9 @@ static int deflate_state(State *s) { return s->state; guard = calcguard(s); -/*fprintf(stderr,"guard:%d pos:%d nin:%d\n", guard, s->pos, s->inend - s->in);*/ for (;;) { if (s->pos >= guard || s->lz - s->lzbuf >= LzGuard) { -/*fprintf(stderr,"guard:%d pos:%d len:%d lzlen:%d end:%d start:%d nin:%d\n", guard, s->pos, s->pos - s->startpos, s->lz - s->lzbuf, s->endpos, s->startpos, s->inend - s->in);*/ +/*fprintf(stderr,"guard:%d pos:%d len:%d lzlen:%d end:%d start:%d nin:%d eof:%d\n", guard, s->pos, s->pos - s->startpos, s->lz - s->lzbuf, s->endpos, s->startpos, s->inend - s->in, s->eof);*/ if (endblock(s)) return (s->state = FlateOut); if (!fillsrc(s))