summaryrefslogtreecommitdiffstats
path: root/encoder.c
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-06 11:39:32 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-06 11:39:32 +0000
commitb54746257408488a8d0b5c86f1c0ab9a66047ed4 (patch)
tree43affae2aaf3a28479a3271daafa33267269dd21 /encoder.c
parentAdding upstream version 1.5~pre2. (diff)
downloadclzip-b54746257408488a8d0b5c86f1c0ab9a66047ed4.tar.xz
clzip-b54746257408488a8d0b5c86f1c0ab9a66047ed4.zip
Adding upstream version 1.5~rc1.upstream/1.5_rc1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'encoder.c')
-rw-r--r--encoder.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/encoder.c b/encoder.c
index 312c569..66358cb 100644
--- a/encoder.c
+++ b/encoder.c
@@ -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;