]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix setParameter not falling back to default compression level on 0 value
authori-do-cpp <62053234+i-do-cpp@users.noreply.github.com>
Mon, 31 Aug 2020 07:25:43 +0000 (09:25 +0200)
committerGitHub <noreply@github.com>
Mon, 31 Aug 2020 07:25:43 +0000 (09:25 +0200)
See documentation for `ZSTD_c_compressionLevel`: `Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT`

lib/compress/zstd_compress.c

index a5ffcf1ea78fdc20b56edf79d4ca8b298f215d05..25160d0d9197aa47c0ad0a7370e9b7e6fb0cab1e 100644 (file)
@@ -540,7 +540,9 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams,
 
     case ZSTD_c_compressionLevel : {
         FORWARD_IF_ERROR(ZSTD_cParam_clampBounds(param, &value), "");
-        if (value) {  /* 0 : does not change current level */
+        if (value == 0)
+            CCtxParams->compressionLevel = ZSTD_CLEVEL_DEFAULT; /* 0 == default */
+        else
             CCtxParams->compressionLevel = value;
         }
         if (CCtxParams->compressionLevel >= 0) return (size_t)CCtxParams->compressionLevel;