diff options
Diffstat (limited to '')
-rw-r--r-- | decoder.c | 35 |
1 files changed, 13 insertions, 22 deletions
@@ -1,5 +1,5 @@ /* Clzip - LZMA lossless data compressor - Copyright (C) 2010-2021 Antonio Diaz Diaz. + Copyright (C) 2010-2022 Antonio Diaz Diaz. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,8 +29,8 @@ #include "decoder.h" -/* Returns the number of bytes really read. - If (returned value < size) and (errno == 0), means EOF was reached. +/* Return the number of bytes really read. + If (value returned < size) and (errno == 0), means EOF was reached. */ int readblock( const int fd, uint8_t * const buf, const int size ) { @@ -48,8 +48,8 @@ int readblock( const int fd, uint8_t * const buf, const int size ) } -/* Returns the number of bytes really written. - If (returned value < size), it is always an error. +/* Return the number of bytes really written. + If (value returned < size), it is always an error. */ int writeblock( const int fd, const uint8_t * const buf, const int size ) { @@ -105,8 +105,6 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d, int size = Rd_read_data( d->rdec, trailer, Lt_size ); const unsigned long long data_size = LZd_data_position( d ); const unsigned long long member_size = Rd_member_position( d->rdec ); - unsigned td_crc; - unsigned long long td_size, tm_size; bool error = false; if( size < Lt_size ) @@ -121,7 +119,7 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d, while( size < Lt_size ) trailer[size++] = 0; } - td_crc = Lt_get_data_crc( trailer ); + const unsigned td_crc = Lt_get_data_crc( trailer ); if( td_crc != LZd_crc( d ) ) { error = true; @@ -132,7 +130,7 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d, td_crc, LZd_crc( d ) ); } } - td_size = Lt_get_data_size( trailer ); + const unsigned long long td_size = Lt_get_data_size( trailer ); if( td_size != data_size ) { error = true; @@ -143,7 +141,7 @@ static bool LZd_verify_trailer( struct LZ_decoder * const d, td_size, td_size, data_size, data_size ); } } - tm_size = Lt_get_member_size( trailer ); + const unsigned long long tm_size = Lt_get_member_size( trailer ); if( tm_size != member_size ) { error = true; @@ -213,25 +211,19 @@ int LZd_decode_member( struct LZ_decoder * const d, Rd_load( rdec ); while( !Rd_finished( rdec ) ) { - int len; const int pos_state = LZd_data_position( d ) & pos_state_mask; if( Rd_decode_bit( rdec, &bm_match[state][pos_state] ) == 0 ) /* 1st bit */ { /* literal byte */ Bit_model * const bm = bm_literal[get_lit_state(LZd_peek_prev( d ))]; - if( St_is_char( state ) ) - { - state -= ( state < 4 ) ? state : 3; + if( ( state = St_set_char( state ) ) < 4 ) LZd_put_byte( d, Rd_decode_tree8( rdec, bm ) ); - } else - { - state -= ( state < 10 ) ? 3 : 6; LZd_put_byte( d, Rd_decode_matched( rdec, bm, LZd_peek( d, rep0 ) ) ); - } continue; } /* match or repeated match */ + int len; if( Rd_decode_bit( rdec, &bm_rep[state] ) != 0 ) /* 2nd bit */ { if( Rd_decode_bit( rdec, &bm_rep0[state] ) == 0 ) /* 3rd bit */ @@ -257,13 +249,12 @@ int LZd_decode_member( struct LZ_decoder * const d, rep0 = distance; } state = St_set_rep( state ); - len = min_match_len + Rd_decode_len( rdec, &rep_len_model, pos_state ); + len = Rd_decode_len( rdec, &rep_len_model, pos_state ); } else /* match */ { - unsigned distance; - len = min_match_len + Rd_decode_len( rdec, &match_len_model, pos_state ); - distance = Rd_decode_tree6( rdec, bm_dis_slot[get_len_state(len)] ); + len = Rd_decode_len( rdec, &match_len_model, pos_state ); + unsigned distance = Rd_decode_tree6( rdec, bm_dis_slot[get_len_state(len)] ); if( distance >= start_dis_model ) { const unsigned dis_slot = distance; |