diff options
author | Yann Collet <cyan@fb.com> | 2017-10-31 00:47:54 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2017-10-31 00:47:54 (GMT) |
commit | 931c5c20d0d87e706e3dd9bf57e089500455c987 (patch) | |
tree | cd1682651ffa50e1adc76d78adf6bf7049970461 /lib/lz4opt.h | |
parent | ab4bd93f59dce5d116f1c95373a64cc39ccd6990 (diff) | |
download | lz4-931c5c20d0d87e706e3dd9bf57e089500455c987.zip lz4-931c5c20d0d87e706e3dd9bf57e089500455c987.tar.gz lz4-931c5c20d0d87e706e3dd9bf57e089500455c987.tar.bz2 |
fixed minor overflow mistake in optimal parser
saving 20 bytes on calgary.tar
Diffstat (limited to 'lib/lz4opt.h')
-rw-r--r-- | lib/lz4opt.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/lz4opt.h b/lib/lz4opt.h index 2daf17e..40592df 100644 --- a/lib/lz4opt.h +++ b/lib/lz4opt.h @@ -328,7 +328,10 @@ static int LZ4HC_compress_optimal ( //nb_matches = LZ4HC_BinTree_GetAllMatches(ctx, curPtr, matchlimit, MINMATCH-1, matches, fullUpdate); nb_matches = LZ4HC_HashChain_GetAllMatches(ctx, curPtr, matchlimit, MINMATCH-1, matches, fullUpdate); //nb_matches = LZ4HC_HashChain_GetAllMatches(ctx, curPtr, matchlimit, last_match_pos - cur + 1, matches, fullUpdate); /* only works if last_match_pos is really the last match pos */ - if ((nb_matches > 0) && (size_t)matches[nb_matches-1].len > sufficient_len) { + if (!nb_matches) continue; + + if ( ((size_t)matches[nb_matches-1].len > sufficient_len) + || (matches[nb_matches-1].len + cur >= LZ4_OPT_NUM) ) { /* immediate encoding */ best_mlen = matches[nb_matches-1].len; best_off = matches[nb_matches-1].off; @@ -357,6 +360,7 @@ static int LZ4HC_compress_optimal ( } if (pos > last_match_pos || price < opt[pos].price) { + assert(pos < LZ4_OPT_NUM); while (last_match_pos < pos) opt[++last_match_pos].price = 1<<30; opt[pos].mlen = ml; opt[pos].off = offset; |