diff options
Diffstat (limited to '')
-rw-r--r-- | encoder.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -73,7 +73,8 @@ bool Mf_init( struct Matchfinder * const mf, const int dict_size, const int match_len_limit, const int ifd ) { const int buffer_size_limit = ( 2 * dict_size ) + before_size + after_size; - int i, size; + unsigned size; + int i; mf->partial_data_pos = 0; mf->match_len_limit = match_len_limit; @@ -105,7 +106,7 @@ bool Mf_init( struct Matchfinder * const mf, mf->pos_limit = mf->buffer_size; if( !mf->at_stream_end ) mf->pos_limit -= after_size; size = 1 << max( 16, real_bits( mf->dictionary_size - 1 ) - 2 ); - if( mf->dictionary_size > 1 << 26 ) + if( mf->dictionary_size > 1 << 26 ) /* 64 MiB */ size >>= 1; mf->key4_mask = size - 1; size += num_prev_positions2; @@ -113,7 +114,8 @@ bool Mf_init( struct Matchfinder * const mf, mf->num_prev_positions = size; size += ( 2 * ( mf->dictionary_size + 1 ) ); - mf->prev_positions = (int32_t *)malloc( size * sizeof (int32_t) ); + if( size * sizeof (int32_t) <= size ) mf->prev_positions = 0; + else mf->prev_positions = (int32_t *)malloc( size * sizeof (int32_t) ); if( !mf->prev_positions ) { free( mf->buffer ); return false; } mf->prev_pos_tree = mf->prev_positions + mf->num_prev_positions; for( i = 0; i < mf->num_prev_positions; ++i ) mf->prev_positions[i] = -1; |