summaryrefslogtreecommitdiffstats
path: root/decoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 07:23:45 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 07:23:45 +0000
commit2f1db1facab89cd2eda64441f9b730a3831f5746 (patch)
tree85afd6f51fae791905b39e7ec5e6d7aa6c79227d /decoder.cc
parentAdding debian version 1.6~pre2-1. (diff)
downloadlzip-2f1db1facab89cd2eda64441f9b730a3831f5746.tar.xz
lzip-2f1db1facab89cd2eda64441f9b730a3831f5746.zip
Merging upstream version 1.6~pre3.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'decoder.cc')
-rw-r--r--decoder.cc33
1 files changed, 21 insertions, 12 deletions
diff --git a/decoder.cc b/decoder.cc
index aeac2cd..0cb6188 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -17,6 +17,7 @@
#define _FILE_OFFSET_BITS 64
+#include <algorithm>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
@@ -45,16 +46,15 @@ bool Input_buffer::read_block()
void LZ_decoder::flush_data()
{
- if( !member_finished )
+ const int size = pos - stream_pos;
+ if( size > 0 )
{
- crc32.update( crc_, buffer, pos );
- if( odes_ >= 0 )
- {
- const int wr = writeblock( odes_, (char *)buffer, pos );
- if( wr != pos ) throw Error( "write error" );
- }
+ crc32.update( crc_, buffer + stream_pos, size );
+ if( odes_ >= 0 &&
+ writeblock( odes_, (char *)buffer + stream_pos, size ) != size )
+ throw Error( "write error" );
if( pos >= buffer_size ) { partial_data_pos += pos; pos = 0; }
- else member_finished = true;
+ stream_pos = pos;
}
}
@@ -180,9 +180,8 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
}
else
{
- rep3 = rep2; rep2 = rep1; rep1 = rep0;
+ unsigned int rep0_saved = rep0;
len = min_match_len + len_decoder.decode( range_decoder, pos_state );
- state.set_match();
const int dis_slot = range_decoder.decode_tree( bm_dis_slot[get_dis_state(len)], dis_slot_bits );
if( dis_slot < start_dis_model ) rep0 = dis_slot;
else
@@ -197,10 +196,17 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
rep0 += range_decoder.decode_tree_reversed( bm_align, dis_align_bits );
if( rep0 == 0xFFFFFFFF ) // Marker found
{
+ rep0 = rep0_saved;
range_decoder.normalize();
flush_data();
if( len == min_match_len ) // End Of Stream marker
- { if( verify_trailer( pp ) ) return 0; else return 3; }
+ {
+ if( verify_trailer( pp ) ) return 0; else return 3;
+ }
+ if( len == min_match_len + 1 ) // Sync Flush marker
+ {
+ range_decoder.reload(); continue;
+ }
if( verbosity >= 0 )
{
pp();
@@ -208,9 +214,12 @@ int LZ_decoder::decode_member( const Pretty_print & pp )
}
return 4;
}
- if( rep0 >= (unsigned int)buffer_size ) { flush_data(); return 1; }
+ if( rep0 >= (unsigned int)dictionary_size )
+ { flush_data(); return 1; }
}
}
+ rep3 = rep2; rep2 = rep1; rep1 = rep0_saved;
+ state.set_match();
}
copy_block( rep0, len );
prev_byte = get_byte( 0 );