ext/libmspack/mspack/readhuff.h in libmspack-0.0.4 vs ext/libmspack/mspack/readhuff.h in libmspack-0.0.5

- old
+ new

@@ -1,19 +1,18 @@ /* This file is part of libmspack. - * (C) 2003-2010 Stuart Caie. + * (C) 2003-2014 Stuart Caie. * * libmspack is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License (LGPL) version 2.1 * * For further details, see the file COPYING.LIB distributed with libmspack */ #ifndef MSPACK_READHUFF_H #define MSPACK_READHUFF_H 1 -/* This implements a fast Huffman tree decoding system. - */ +/* This implements a fast Huffman tree decoding system. */ #if !(defined(BITS_ORDER_MSB) || defined(BITS_ORDER_LSB)) # error "readhuff.h is used in conjunction with readbits.h, include that first" #endif #if !(defined(TABLEBITS) && defined(MAXSYMBOLS)) @@ -138,10 +137,11 @@ bit_mask = 1 << 15; for (bit_num = nbits+1; bit_num <= HUFF_MAXBITS; bit_num++) { for (sym = 0; sym < nsyms; sym++) { if (length[sym] != bit_num) continue; + if (pos >= table_mask) return 1; /* table overflow */ #ifdef BITS_ORDER_MSB leaf = pos >> 16; #else /* leaf = the first nbits of the code, reversed */ @@ -159,11 +159,10 @@ /* follow the path and select either left or right for next bit */ leaf = table[leaf] << 1; if ((pos >> (15-fill)) & 1) leaf++; } table[leaf] = sym; - - if ((pos += bit_mask) > table_mask) return 1; /* table overflow */ + pos += bit_mask; } bit_mask >>= 1; } /* full table? */