diff options
Diffstat (limited to 'decoder.c')
-rw-r--r-- | decoder.c | 37 |
1 files changed, 16 insertions, 21 deletions
@@ -1,5 +1,5 @@ /* Clzip - Data compressor based on the LZMA algorithm - Copyright (C) 2010, 2011 Antonio Diaz Diaz. + Copyright (C) 2010, 2011, 2012 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 @@ -65,7 +65,7 @@ int writeblock( const int fd, const uint8_t * const buf, const int size ) if( rest <= 0 ) break; n = write( fd, buf + size - rest, rest ); if( n > 0 ) rest -= n; - else if( errno && errno != EINTR && errno != EAGAIN ) break; + else if( n < 0 && errno != EINTR && errno != EAGAIN ) break; } return ( rest > 0 ) ? size - rest : size; } @@ -91,7 +91,7 @@ void LZd_flush_data( struct LZ_decoder * const decoder ) const int size = decoder->pos - decoder->stream_pos; if( size > 0 ) { - CRC32_update_buf( &decoder->crc_, decoder->buffer + decoder->stream_pos, size ); + CRC32_update_buf( &decoder->crc, decoder->buffer + decoder->stream_pos, size ); if( decoder->outfd >= 0 && writeblock( decoder->outfd, decoder->buffer + decoder->stream_pos, size ) != size ) { show_error( "Write error", errno, false ); cleanup_and_fail( 1 ); } @@ -105,31 +105,26 @@ void LZd_flush_data( struct LZ_decoder * const decoder ) bool LZd_verify_trailer( struct LZ_decoder * const decoder, struct Pretty_print * const pp ) { - int i; File_trailer trailer; const int trailer_size = Ft_versioned_size( decoder->member_version ); const long long member_size = Rd_member_position( decoder->range_decoder ) + trailer_size; bool error = false; - for( i = 0; i < trailer_size && !error; ++i ) + int size = Rd_read_data( decoder->range_decoder, trailer, trailer_size ); + if( size < trailer_size ) { - if( !Rd_finished( decoder->range_decoder ) ) - trailer[i] = Rd_get_byte( decoder->range_decoder ); - else + error = true; + if( pp->verbosity >= 0 ) { - error = true; - if( pp->verbosity >= 0 ) - { - Pp_show_msg( pp, 0 ); - fprintf( stderr, "Trailer truncated at trailer position %d;" - " some checks may fail.\n", i ); - } - for( ; i < trailer_size; ++i ) trailer[i] = 0; + Pp_show_msg( pp, 0 ); + fprintf( stderr, "Trailer truncated at trailer position %d;" + " some checks may fail.\n", size ); } + while( size < trailer_size ) trailer[size++] = 0; } if( decoder->member_version == 0 ) Ft_set_member_size( trailer, member_size ); - if( !Rd_code_is_zero( decoder->range_decoder ) ) + if( decoder->range_decoder->code != 0 ) { error = true; Pp_show_msg( pp, "Range decoder final code is not zero" ); @@ -190,11 +185,9 @@ int LZd_decode_member( struct LZ_decoder * const decoder, State state = 0; Rd_load( decoder->range_decoder ); - while( true ) + while( !Rd_finished( decoder->range_decoder ) ) { const int pos_state = LZd_data_position( decoder ) & pos_state_mask; - if( Rd_finished( decoder->range_decoder ) ) - { LZd_flush_data( decoder ); return 2; } if( Rd_decode_bit( decoder->range_decoder, &decoder->bm_match[state][pos_state] ) == 0 ) { const uint8_t prev_byte = LZd_get_prev_byte( decoder ); @@ -271,7 +264,7 @@ int LZd_decode_member( struct LZ_decoder * const decoder, if( pp->verbosity >= 0 ) { Pp_show_msg( pp, 0 ); - fprintf( stderr, "Unsupported marker code `%d'.\n", len ); + fprintf( stderr, "Unsupported marker code '%d'.\n", len ); } return 4; } @@ -286,4 +279,6 @@ int LZd_decode_member( struct LZ_decoder * const decoder, LZd_copy_block( decoder, rep0, len ); } } + LZd_flush_data( decoder ); + return 2; } |