From: Nick Terrell Date: Mon, 12 Oct 2020 21:12:23 +0000 (-0700) Subject: [lib] Compress directly into output when ZSTD_c_stableOutBuffer is set X-Git-Tag: v1.4.7~38^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d5dc93d4e34c8420e4fa2779b704ad4ce61df2c;p=thirdparty%2Fzstd.git [lib] Compress directly into output when ZSTD_c_stableOutBuffer is set When we have a stable output buffer always compress directly into the `ZSTD_outBuffer`. We are allowed to return `dstSizeTooSmall`. --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index acd150b9d..1c8fb2fc2 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -4104,7 +4104,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs, size_t const iSize = zcs->inBuffPos - zcs->inToCompress; size_t oSize = oend-op; unsigned const lastBlock = (flushMode == ZSTD_e_end) && (ip==iend); - if (oSize >= ZSTD_compressBound(iSize)) + if (oSize >= ZSTD_compressBound(iSize) || zcs->appliedParams.outBufferMode == ZSTD_bm_stable) cDst = op; /* compress into output buffer, to skip flush stage */ else cDst = zcs->outBuff, oSize = zcs->outBuffSize; @@ -4140,6 +4140,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs, /* fall-through */ case zcss_flush: DEBUGLOG(5, "flush stage"); + assert(zcs->appliedParams.outBufferMode == ZSTD_bm_buffered); { size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; size_t const flushed = ZSTD_limitCopy(op, (size_t)(oend-op), zcs->outBuff + zcs->outBuffFlushedSize, toFlush);