summaryrefslogtreecommitdiffstats
path: root/lzd.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2016-02-21 12:41:43 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2016-05-12 14:53:53 +0000
commitd892e74a10fe6758f89af3c9af063dff5a8f99b2 (patch)
tree6bdc14fbe995d0755f0034ea0bcdc12056a8fd01 /lzd.cc
parentAdding debian version 0.7-1. (diff)
downloadlzd-d892e74a10fe6758f89af3c9af063dff5a8f99b2.tar.xz
lzd-d892e74a10fe6758f89af3c9af063dff5a8f99b2.zip
Merging upstream version 0.8.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'lzd.cc')
-rw-r--r--lzd.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/lzd.cc b/lzd.cc
index 30dde48..5f8dcdc 100644
--- a/lzd.cc
+++ b/lzd.cc
@@ -1,5 +1,5 @@
/* Lzd - Educational decompressor for the lzip format
- Copyright (C) 2013-2015 Antonio Diaz Diaz.
+ Copyright (C) 2013-2016 Antonio Diaz Diaz.
This program is free software: you have unlimited permission
to copy, distribute and modify it.
@@ -52,6 +52,7 @@ enum {
min_dictionary_size = 1 << 12,
max_dictionary_size = 1 << 29,
literal_context_bits = 3,
+ literal_pos_state_bits = 0, // not used
pos_state_bits = 2,
pos_states = 1 << pos_state_bits,
pos_state_mask = pos_states - 1,
@@ -238,6 +239,7 @@ class LZ_decoder
unsigned pos; // current pos in buffer
unsigned stream_pos; // first byte not yet written to stdout
uint32_t crc_;
+ bool pos_wrapped;
void flush_data();
@@ -262,7 +264,8 @@ public:
buffer( new uint8_t[dictionary_size] ),
pos( 0 ),
stream_pos( 0 ),
- crc_( 0xFFFFFFFFU )
+ crc_( 0xFFFFFFFFU ),
+ pos_wrapped( false )
{ buffer[dictionary_size-1] = 0; } // prev_byte of first byte
~LZ_decoder() { delete[] buffer; }
@@ -284,7 +287,8 @@ void LZ_decoder::flush_data()
if( std::fwrite( buffer + stream_pos, 1, size, stdout ) != size )
{ std::fprintf( stderr, "Write error: %s\n", std::strerror( errno ) );
std::exit( 1 ); }
- if( pos >= dictionary_size ) { partial_data_pos += pos; pos = 0; }
+ if( pos >= dictionary_size )
+ { partial_data_pos += pos; pos = 0; pos_wrapped = true; }
stream_pos = pos;
}
}
@@ -380,7 +384,7 @@ bool LZ_decoder::decode_member() // Returns false if error
}
}
state.set_match();
- if( rep0 >= dictionary_size || rep0 >= data_position() )
+ if( rep0 >= dictionary_size || ( rep0 >= pos && !pos_wrapped ) )
{ flush_data(); return false; }
}
for( int i = 0; i < len; ++i ) put_byte( peek( rep0 ) );
@@ -402,7 +406,7 @@ int main( const int argc, const char * const argv[] )
"It is not safe to use lzd for any real work.\n"
"\nUsage: %s < file.lz > file\n", argv[0] );
std::printf( "Lzd decompresses from standard input to standard output.\n"
- "\nCopyright (C) 2015 Antonio Diaz Diaz.\n"
+ "\nCopyright (C) 2016 Antonio Diaz Diaz.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"Report bugs to lzip-bug@nongnu.org\n"