Merge pull request #1458 from terrelln/estimate

[libzstd] Fix estimate with negative levels
dev
Yann Collet 2018-12-18 15:12:21 -08:00 committed by GitHub
commit d0e15f8d32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -1013,7 +1013,7 @@ size_t ZSTD_estimateCCtxSize(int compressionLevel)
{
int level;
size_t memBudget = 0;
for (level=1; level<=compressionLevel; level++) {
for (level=MIN(compressionLevel, 1); level<=compressionLevel; level++) {
size_t const newMB = ZSTD_estimateCCtxSize_internal(level);
if (newMB > memBudget) memBudget = newMB;
}
@ -1049,7 +1049,7 @@ size_t ZSTD_estimateCStreamSize(int compressionLevel)
{
int level;
size_t memBudget = 0;
for (level=1; level<=compressionLevel; level++) {
for (level=MIN(compressionLevel, 1); level<=compressionLevel; level++) {
size_t const newMB = ZSTD_estimateCStreamSize_internal(level);
if (newMB > memBudget) memBudget = newMB;
}

View File

@ -694,6 +694,17 @@ static int basicUnitTests(U32 seed, double compressibility)
free(staticDCtxBuffer);
}
DISPLAYLEVEL(3, "test%3i : Static negative levels : ", testNb++);
{ size_t const cctxSizeN1 = ZSTD_estimateCCtxSize(-1);
size_t const cctxSizeP1 = ZSTD_estimateCCtxSize(1);
size_t const cstreamSizeN1 = ZSTD_estimateCStreamSize(-1);
size_t const cstreamSizeP1 = ZSTD_estimateCStreamSize(1);
if (!(0 < cctxSizeN1 && cctxSizeN1 <= cctxSizeP1)) goto _output_error;
if (!(0 < cstreamSizeN1 && cstreamSizeN1 <= cstreamSizeP1)) goto _output_error;
}
DISPLAYLEVEL(3, "OK \n");
/* ZSTDMT simple MT compression test */
DISPLAYLEVEL(3, "test%3i : create ZSTDMT CCtx : ", testNb++);