"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "decoder.c" between
lzlib-1.11.tar.lz and lzlib-1.12-rc1.tar.lz

About: Lzlib is a data compression library providing in-memory LZMA compression and decompression functions using the lzip format. Release candidate.

decoder.c  (lzlib-1.11.tar.lz):decoder.c  (lzlib-1.12-rc1.tar.lz)
/* Lzlib - Compression library for the lzip format /* Lzlib - Compression library for the lzip format
Copyright (C) 2009-2019 Antonio Diaz Diaz. Copyright (C) 2009-2020 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided
that the following conditions are met: that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/ */
static int LZd_try_verify_trailer( struct LZ_decoder * const d ) static int LZd_try_verify_trailer( struct LZ_decoder * const d )
{ {
Lzip_trailer trailer; Lzip_trailer trailer;
if( Rd_available_bytes( d->rdec ) < Lt_size && !d->rdec->at_stream_end ) if( Rd_available_bytes( d->rdec ) < Lt_size )
return 0; { if( !d->rdec->at_stream_end ) return 0; else return 2; }
d->verify_trailer_pending = false; d->verify_trailer_pending = false;
d->member_finished = true; d->member_finished = true;
if( Rd_read_data( d->rdec, trailer, Lt_size ) == Lt_size && if( Rd_read_data( d->rdec, trailer, Lt_size ) == Lt_size &&
Lt_get_data_crc( trailer ) == LZd_crc( d ) && Lt_get_data_crc( trailer ) == LZd_crc( d ) &&
Lt_get_data_size( trailer ) == LZd_data_position( d ) && Lt_get_data_size( trailer ) == LZd_data_position( d ) &&
Lt_get_member_size( trailer ) == d->rdec->member_position ) return 0; Lt_get_member_size( trailer ) == d->rdec->member_position ) return 0;
return 3; return 3;
} }
/* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF, /* Return value: 0 = OK, 1 = decoder error, 2 = unexpected EOF,
3 = trailer error, 4 = unknown marker found, 3 = trailer error, 4 = unknown marker found,
5 = library error. */ 5 = library error. */
static int LZd_decode_member( struct LZ_decoder * const d ) static int LZd_decode_member( struct LZ_decoder * const d )
{ {
struct Range_decoder * const rdec = d->rdec; struct Range_decoder * const rdec = d->rdec;
State * const state = &d->state; State * const state = &d->state;
/* unsigned old_mpos = d->rdec->member_position; */ unsigned old_mpos = rdec->member_position;
if( d->member_finished ) return 0; if( d->member_finished ) return 0;
if( !Rd_try_reload( rdec, false ) ) if( !Rd_try_reload( rdec ) )
{ if( !rdec->at_stream_end ) return 0; else return 2; } { if( !rdec->at_stream_end ) return 0; else return 2; }
if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d ); if( d->verify_trailer_pending ) return LZd_try_verify_trailer( d );
while( !Rd_finished( rdec ) ) while( !Rd_finished( rdec ) )
{ {
int len; int len;
const int pos_state = LZd_data_position( d ) & pos_state_mask; const int pos_state = LZd_data_position( d ) & pos_state_mask;
/* const unsigned mpos = d->rdec->member_position; const unsigned mpos = rdec->member_position;
if( mpos - old_mpos > rd_min_available_bytes ) return 5; if( mpos - old_mpos > rd_min_available_bytes ) return 5;
old_mpos = mpos; */ old_mpos = mpos;
if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */ if( !Rd_enough_available_bytes( rdec ) ) /* check unexpected EOF */
{ if( !rdec->at_stream_end ) return 0; { if( !rdec->at_stream_end ) return 0;
if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */ if( Cb_empty( &rdec->cb ) ) break; } /* decode until EOF */
if( !LZd_enough_free_bytes( d ) ) return 0; if( !LZd_enough_free_bytes( d ) ) return 0;
if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */ if( Rd_decode_bit( rdec, &d->bm_match[*state][pos_state] ) == 0 ) /* 1st bit */
{ {
/* literal byte */ /* literal byte */
Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))]; Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev( d ))];
if( St_is_char( *state ) ) if( St_is_char( *state ) )
{ {
skipping to change at line 125 skipping to change at line 125
distance += Rd_decode_tree_reversed( rdec, distance += Rd_decode_tree_reversed( rdec,
d->bm_dis + ( distance - dis_slot ), direct_bits ); d->bm_dis + ( distance - dis_slot ), direct_bits );
else else
{ {
distance += distance +=
Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits; Rd_decode( rdec, direct_bits - dis_align_bits ) << dis_align_bits;
distance += Rd_decode_tree_reversed4( rdec, d->bm_align ); distance += Rd_decode_tree_reversed4( rdec, d->bm_align );
if( distance == 0xFFFFFFFFU ) /* marker found */ if( distance == 0xFFFFFFFFU ) /* marker found */
{ {
Rd_normalize( rdec ); Rd_normalize( rdec );
if( (unsigned)rdec->member_position - old_mpos > rd_min_available_by
tes )
return 5;
if( len == min_match_len ) /* End Of Stream marker */ if( len == min_match_len ) /* End Of Stream marker */
{ {
d->verify_trailer_pending = true; d->verify_trailer_pending = true;
return LZd_try_verify_trailer( d ); return LZd_try_verify_trailer( d );
} }
if( len == min_match_len + 1 ) /* Sync Flush marker */ if( len == min_match_len + 1 ) /* Sync Flush marker */
{ {
if( Rd_try_reload( rdec, true ) ) { /*old_mpos += 5;*/ continue; } rdec->reload_pending = true;
if( Rd_try_reload( rdec ) ) { old_mpos += 5; continue; }
else { if( !rdec->at_stream_end ) return 0; else break; } else { if( !rdec->at_stream_end ) return 0; else break; }
} }
return 4; return 4;
} }
} }
} }
d->rep3 = d->rep2; d->rep2 = d->rep1; d->rep1 = d->rep0; d->rep0 = distanc e; d->rep3 = d->rep2; d->rep2 = d->rep1; d->rep1 = d->rep0; d->rep0 = distanc e;
*state = St_set_match( *state ); *state = St_set_match( *state );
if( d->rep0 >= d->dictionary_size || if( d->rep0 >= d->dictionary_size ||
( d->rep0 >= d->cb.put && !d->pos_wrapped ) ) return 1; ( d->rep0 >= d->cb.put && !d->pos_wrapped ) ) return 1;
 End of changes. 9 change blocks. 
23 lines changed or deleted 27 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)