]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fix sizeof_CCtx and sizeof_CDict Calculations for Statically Init'ed Objects
authorW. Felix Handte <w@felixhandte.com>
Mon, 9 Sep 2019 20:45:17 +0000 (16:45 -0400)
committerW. Felix Handte <w@felixhandte.com>
Mon, 9 Sep 2019 20:45:17 +0000 (16:45 -0400)
lib/compress/zstd_compress.c

index 7adcb7c1ead9be8cc02820c8aa9a44189b7cced2..c8b031f85e64b240d653787b8d7e85581b0f8b51 100644 (file)
@@ -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(