X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fxpress_compress.c;h=cf29df99268d2801e97cdab246c44392d1bfdea9;hb=0497587f1cf98171731480a0444624eb47a8560a;hp=65c4b026627bdeaf912b29e04cdba435779f7cef;hpb=3e8aa757aaa63297f0d54007adf46411778fb6a8;p=wimlib diff --git a/src/xpress_compress.c b/src/xpress_compress.c index 65c4b026..cf29df99 100644 --- a/src/xpress_compress.c +++ b/src/xpress_compress.c @@ -1031,7 +1031,8 @@ xpress_get_compressor_size(size_t max_bufsize, unsigned compression_level) } static u64 -xpress_get_needed_memory(size_t max_bufsize, unsigned compression_level) +xpress_get_needed_memory(size_t max_bufsize, unsigned compression_level, + bool destructive) { u64 size = 0; @@ -1060,7 +1061,7 @@ xpress_get_needed_memory(size_t max_bufsize, unsigned compression_level) static int xpress_create_compressor(size_t max_bufsize, unsigned compression_level, - void **c_ret) + bool destructive, void **c_ret) { struct xpress_compressor *c; @@ -1088,6 +1089,13 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level, c->impl = xpress_compress_lazy; c->max_search_depth = (compression_level * 24) / 32; c->nice_match_length = (compression_level * 48) / 32; + + /* xpress_compress_lazy() needs max_search_depth >= 2 + * because it halves the max_search_depth when + * attempting a lazy match, and max_search_depth cannot + * be 0. */ + if (c->max_search_depth < 2) + c->max_search_depth = 2; } } #if SUPPORT_NEAR_OPTIMAL_PARSING @@ -1113,6 +1121,10 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level, } #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */ + /* max_search_depth == 0 is invalid. */ + if (c->max_search_depth < 1) + c->max_search_depth = 1; + *c_ret = c; return 0;