X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flzms-compress.c;h=2f87fd4320bcc7ebf2baa204724c4884d0aeb330;hb=343b098498118f1554bd476d00d8233ec0cb9a6b;hp=a696e261a3d331b88084f037af6124f6485f6c0a;hpb=383d06fc4beb7169ade7d694ae056c51a0d12fbb;p=wimlib diff --git a/src/lzms-compress.c b/src/lzms-compress.c index a696e261..2f87fd43 100644 --- a/src/lzms-compress.c +++ b/src/lzms-compress.c @@ -45,8 +45,6 @@ #include #include -#define LZMS_OPTIM_ARRAY_SIZE 1024 - struct lzms_compressor; struct lzms_adaptive_state { struct lzms_lz_lru_queues lru; @@ -877,9 +875,10 @@ lzms_get_near_optimal_match(struct lzms_compressor *ctx) * - The costs of literals and matches are estimated using the range encoder * states and the semi-adaptive Huffman codes. Except for range encoding * states, costs are assumed to be constant throughout a single run of the - * parsing algorithm, which can parse up to LZMS_OPTIM_ARRAY_SIZE bytes of - * data. This introduces a source of inaccuracy because the probabilities and - * Huffman codes can change over this part of the data. + * parsing algorithm, which can parse up to @optim_array_length (from the + * `struct wimlib_lzms_compressor_params') bytes of data. This introduces a + * source of inaccuracy because the probabilities and Huffman codes can change + * over this part of the data. */ static void lzms_encode(struct lzms_compressor *ctx) @@ -1169,7 +1168,9 @@ lzms_free_compressor(void *_ctx) } static const struct wimlib_lzms_compressor_params lzms_default = { - .hdr = sizeof(struct wimlib_lzms_compressor_params), + .hdr = { + .size = sizeof(struct wimlib_lzms_compressor_params), + }, .min_match_length = 2, .max_match_length = UINT32_MAX, .nice_match_length = 32, @@ -1178,6 +1179,9 @@ static const struct wimlib_lzms_compressor_params lzms_default = { .optim_array_length = 1024, }; +static bool +lzms_params_valid(const struct wimlib_compressor_params_header *); + static const struct wimlib_lzms_compressor_params * lzms_get_params(const struct wimlib_compressor_params_header *_params) { @@ -1187,6 +1191,8 @@ lzms_get_params(const struct wimlib_compressor_params_header *_params) if (params == NULL) params = &lzms_default; + LZMS_ASSERT(lzms_params_valid(¶ms->hdr)); + return params; } @@ -1220,7 +1226,7 @@ lzms_create_compressor(size_t max_block_size, if (!lz_sarray_init(&ctx->lz_sarray, max_block_size, params->min_match_length, - params->max_match_length, + min(params->max_match_length, LZ_SARRAY_LEN_MAX), params->max_search_depth, params->max_matches_per_pos)) goto oom;