summaryrefslogtreecommitdiffstats
path: root/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/decoder.h b/decoder.h
index 290ab97..e4444f1 100644
--- a/decoder.h
+++ b/decoder.h
@@ -21,7 +21,7 @@ class Input_buffer
uint8_t * const buffer;
int pos;
int stream_pos; // when reached, a new block must be read
- const int ides_;
+ const int ides_; // input file descriptor
bool at_stream_end;
bool read_block();
@@ -196,11 +196,11 @@ class Literal_decoder
{ return ( prev_byte >> ( 8 - literal_context_bits ) ); }
public:
- uint8_t decode( Range_decoder & range_decoder, const int prev_byte )
+ uint8_t decode( Range_decoder & range_decoder, const uint8_t prev_byte )
{ return range_decoder.decode_tree( bm_literal[state(prev_byte)], 8 ); }
uint8_t decode_matched( Range_decoder & range_decoder,
- const int prev_byte, const int match_byte )
+ const uint8_t prev_byte, const uint8_t match_byte )
{ return range_decoder.decode_matched( bm_literal[state(prev_byte)], match_byte ); }
};
@@ -215,7 +215,7 @@ class LZ_decoder
int pos;
int stream_pos; // first byte not yet written to file
uint32_t crc_;
- const int odes_;
+ const int odes_; // output file descriptor
Bit_model bm_match[State::states][pos_states];
Bit_model bm_rep[State::states];
@@ -249,7 +249,7 @@ class LZ_decoder
{
int i = pos - distance - 1;
if( i < 0 ) i += buffer_size;
- if( len < buffer_size - std::max( pos, i ) && len <= distance )
+ if( len < buffer_size - std::max( pos, i ) && len <= std::abs( pos - i ) )
{
std::memcpy( buffer + pos, buffer + i, len );
pos += len;
@@ -278,7 +278,8 @@ public:
crc_( 0xFFFFFFFF ),
odes_( odes ),
range_decoder( sizeof header, ibuf ),
- literal_decoder() {}
+ literal_decoder()
+ { buffer[buffer_size-1] = 0; } // prev_byte of first_byte
~LZ_decoder() { delete[] buffer; }