]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Creates IS_ENC_DICT_SIZE_VALID() macro.
authorJia Tan <jiat0218@gmail.com>
Mon, 8 May 2023 14:58:09 +0000 (22:58 +0800)
committerJia Tan <jiat0218@gmail.com>
Thu, 11 May 2023 14:28:45 +0000 (22:28 +0800)
This creates an internal liblzma macro to test if the dictionary size
is valid for encoding.

src/liblzma/lz/lz_encoder.c
src/liblzma/lz/lz_encoder.h

index 5489085a08606aa28d730e14550d2d84af489da8..8e724a035a13c64f439d48f1b2d847acd6dc4d33 100644 (file)
@@ -196,9 +196,7 @@ lz_encoder_prepare(lzma_mf *mf, const lzma_allocator *allocator,
        // For now, the dictionary size is limited to 1.5 GiB. This may grow
        // in the future if needed, but it needs a little more work than just
        // changing this check.
-       if (lz_options->dict_size < LZMA_DICT_SIZE_MIN
-                       || lz_options->dict_size
-                               > (UINT32_C(1) << 30) + (UINT32_C(1) << 29)
+       if (!IS_ENC_DICT_SIZE_VALID(lz_options->dict_size)
                        || lz_options->nice_len > lz_options->match_len_max)
                return true;
 
index 7950a2f4ef1bcd086b2abf3ad72d9991e67b512a..2027b39fe1a629b1a3267aacf2e7425cdd2f27c7 100644 (file)
 #include "common.h"
 
 
+// For now, the dictionary size is limited to 1.5 GiB. This may grow
+// in the future if needed, but it needs a little more work than just
+// changing this check.
+#define IS_ENC_DICT_SIZE_VALID(size) \
+       ((size) >= LZMA_DICT_SIZE_MIN \
+                       &&  (size) <= (UINT32_C(1) << 30) + (UINT32_C(1) << 29))
+
+
 /// A table of these is used by the LZ-based encoder to hold
 /// the length-distance pairs found by the match finder.
 typedef struct {