]> wimlib.net Git - wimlib/blobdiff - src/compress.c
lzx-decompress.c: Inline and optimize lzx_decode_match()
[wimlib] / src / compress.c
index 4c99dab145db7b04c5f6fb80f6207d6537b95179..aed609aa7aff560a05e11a2021af3fabdb227749 100644 (file)
@@ -90,6 +90,9 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
        if (!compressor_ctype_valid(ctype))
                return 0;
 
+       if (max_block_size == 0)
+               return 0;
+
        ops = compressor_ops[ctype];
 
        if (compression_level == 0)
@@ -97,10 +100,16 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
        if (compression_level == 0)
                compression_level = DEFAULT_COMPRESSION_LEVEL;
 
-       size = sizeof(struct wimlib_compressor);
-       if (ops->get_needed_memory)
-               size += ops->get_needed_memory(max_block_size, compression_level);
-       return size;
+       if (ops->get_needed_memory) {
+               size = ops->get_needed_memory(max_block_size, compression_level);
+
+               /* 0 is never valid and indicates an invalid max_block_size.  */
+               if (size == 0)
+                       return 0;
+       } else {
+               size = 0;
+       }
+       return size + sizeof(struct wimlib_compressor);
 }
 
 WIMLIBAPI int
@@ -111,15 +120,15 @@ wimlib_create_compressor(enum wimlib_compression_type ctype,
 {
        struct wimlib_compressor *c;
 
+       if (!compressor_ctype_valid(ctype))
+               return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
+
        if (c_ret == NULL)
                return WIMLIB_ERR_INVALID_PARAM;
 
        if (max_block_size == 0)
                return WIMLIB_ERR_INVALID_PARAM;
 
-       if (!compressor_ctype_valid(ctype))
-               return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
-
        c = MALLOC(sizeof(*c));
        if (c == NULL)
                return WIMLIB_ERR_NOMEM;