flate

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

commit 2d40c927d7473c92826756c595461756bfdee095
parent 125cf4e3c02d9e3e8258f164e73dbcc316d18310
Author: nsz <nszabolcs@gmail.com>
Date:   Sun, 21 Jun 2009 21:19:52 +0200

-winmask, +todo
Diffstat:
inflate.c | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/inflate.c b/inflate.c @@ -16,8 +16,7 @@ enum { Ndist = 30, /* number of distance codes */ Nclen = 19, /* number of code length codes */ SrcSize = 1 << 12, /* input buffer size */ - WinSize = 1 << 15, /* output window size */ - WinMask = WinSize - 1 /* window pos (index) mask */ + WinSize = 1 << 15 /* output window size */ }; /* return values */ @@ -180,7 +179,7 @@ static int build_huff(Huff *huff, uchar *lens, uint n, uint nbits) { /* lookup table for decoding nbits from input.. */ for (i = 0; i < 1 << nbits; i++) - table[i].len = 0; /* invalid marker for incomplete code */ + table[i].len = table[i].sym = 0; code = 0; /* ..if code is at most nbits (bits are in reverse order, sigh..) */ for (len = min; len <= nbits; len++) @@ -399,26 +398,26 @@ static int decode_block(State *s, Huff *lhuff, Huff *dhuff) { if (pos + len < WinSize) { /* lenbase[sym] >= 3 */ do { - win[pos] = win[(pos - dist) & WinMask]; + win[pos] = win[(pos - dist) % WinSize]; pos++; - win[pos] = win[(pos - dist) & WinMask]; + win[pos] = win[(pos - dist) % WinSize]; pos++; - win[pos] = win[(pos - dist) & WinMask]; + win[pos] = win[(pos - dist) % WinSize]; pos++; len -= 3; } while (len >= 3); if (len--) { - win[pos] = win[(pos - dist) & WinMask]; + win[pos] = win[(pos - dist) % WinSize]; pos++; if (len) { - win[pos] = win[(pos - dist) & WinMask]; + win[pos] = win[(pos - dist) % WinSize]; pos++; } } } else { /* rare */ case DecodeBlockCopy: while (len--) { - win[pos] = win[(pos - dist) & WinMask]; + win[pos] = win[(pos - dist) % WinSize]; pos++; if (pos == WinSize) { s->pos = pos; @@ -567,6 +566,7 @@ int inflate(State *s) { s->state = DynamicHuffContinue; return FlateNeedInput; } + /* TODO: bound check s->lens */ if (sym == 16) { /* copy previous code length 3-6 times */