From: W. Felix Handte Date: Wed, 14 Aug 2019 18:44:17 +0000 (-0400) Subject: Rewrite ZSTD_initStaticCCtx to Alloc CCtx in Workspace X-Git-Tag: v1.4.4~1^2~57^2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65057cf009a749e66b045b0a709f5e95c6c8abd1;p=thirdparty%2Fzstd.git Rewrite ZSTD_initStaticCCtx to Alloc CCtx in Workspace --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index a8bf0d927..f27698c0d 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -278,12 +278,19 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem) ZSTD_CCtx* ZSTD_initStaticCCtx(void *workspace, size_t workspaceSize) { - ZSTD_CCtx* const cctx = (ZSTD_CCtx*) workspace; + ZSTD_CCtx_workspace tmpWorkspace; + ZSTD_CCtx* cctx; if (workspaceSize <= sizeof(ZSTD_CCtx)) return NULL; /* minimum size */ if ((size_t)workspace & 7) return NULL; /* must be 8-aligned */ + ZSTD_workspace_init(&tmpWorkspace, workspace, workspaceSize); + + cctx = (ZSTD_CCtx*)ZSTD_workspace_reserve_object(&tmpWorkspace, sizeof(ZSTD_CCtx)); + if (cctx == NULL) { + return NULL; + } memset(cctx, 0, sizeof(ZSTD_CCtx)); + cctx->workspace = tmpWorkspace; cctx->staticSize = workspaceSize; - ZSTD_workspace_init(&cctx->workspace, (void*)(cctx+1), workspaceSize - sizeof(ZSTD_CCtx)); /* statically sized space. entropyWorkspace never moves (but prev/next block swap places) */ if (!ZSTD_workspace_check_available(&cctx->workspace, HUF_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compressedBlockState_t))) return NULL;