From: W. Felix Handte Date: Mon, 9 Sep 2019 20:45:17 +0000 (-0400) Subject: Fix sizeof_CCtx and sizeof_CDict Calculations for Statically Init'ed Objects X-Git-Tag: v1.4.4~1^2~57^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb6f69d97838add9d713140999900acdcb8b4c9b;p=thirdparty%2Fzstd.git Fix sizeof_CCtx and sizeof_CDict Calculations for Statically Init'ed Objects --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 7adcb7c1e..c8b031f85 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -166,7 +166,9 @@ static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx) size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx) { if (cctx==NULL) return 0; /* support sizeof on NULL */ - return sizeof(*cctx) + ZSTD_cwksp_sizeof(&cctx->workspace) + /* cctx may be in the workspace */ + return (cctx->workspace.workspace == cctx ? 0 : sizeof(*cctx)) + + ZSTD_cwksp_sizeof(&cctx->workspace) + ZSTD_sizeof_localDict(cctx->localDict) + ZSTD_sizeof_mtctx(cctx); } @@ -3103,7 +3105,9 @@ size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict) { if (cdict==NULL) return 0; /* support sizeof on NULL */ DEBUGLOG(5, "sizeof(*cdict) : %u", (unsigned)sizeof(*cdict)); - return ZSTD_cwksp_sizeof(&cdict->workspace) + sizeof(*cdict); + /* cdict may be in the workspace */ + return (cdict->workspace.workspace == cdict ? 0 : sizeof(*cdict)) + + ZSTD_cwksp_sizeof(&cdict->workspace); } static size_t ZSTD_initCDict_internal(