const U32 updateRate = 2 * BLOCKSIZE;
/* Init */
+ if (maxDstSize < ZSTD_compressBound(srcSize) - 4 /*header size*/) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
if (ctx->base==NULL)
ctx->base = (const BYTE*)src, ctx->current=0, ctx->nextUpdate = g_maxDistance;
if (src != ctx->base + ctx->current) /* not contiguous */
}
/* compress */
- if (maxDstSize < ZSTD_blockHeaderSize) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
cSize = ZSTD_compressBlock(ctx, op+ZSTD_blockHeaderSize, maxDstSize-ZSTD_blockHeaderSize, ip, blockSize);
if (cSize == 0)
{
static size_t ZSTD_compressCCtx(ZSTD_Cctx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
{
BYTE* const ostart = (BYTE* const)dst;
+ BYTE* const oend = ostart + maxDstSize;
BYTE* op = ostart;
/* Header */
/* Compression */
{
- size_t cSize = ZSTD_compressContinue(ctx, op, maxDstSize, src, srcSize);
+ size_t cSize = ZSTD_compressContinue(ctx, op, oend-op, src, srcSize);
if (ZSTD_isError(cSize)) return cSize;
op += cSize;
maxDstSize -= cSize;
/* Close frame */
{
- size_t endSize = ZSTD_compressEnd(ctx, op, maxDstSize);
+ size_t endSize = ZSTD_compressEnd(ctx, op, oend-op);
if(ZSTD_isError(endSize)) return endSize;
op += endSize;
}