]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed too strong alignment assert in ZSTD_initStaticCCtx()
authorYann Collet <cyan@fb.com>
Wed, 13 Sep 2017 23:35:29 +0000 (16:35 -0700)
committerYann Collet <cyan@fb.com>
Wed, 13 Sep 2017 23:35:29 +0000 (16:35 -0700)
64-bits fields are only 32-bits aligned on 32-bits CPU

lib/compress/zstd_compress.c

index 9f59ea686aef2bbc2c00d2c4b72654b6400b2da6..f35a44e4c9f82b67ae92ea2ad8fe158111937334 100644 (file)
@@ -87,7 +87,7 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
 
 ZSTD_CCtx* ZSTD_initStaticCCtx(void *workspace, size_t workspaceSize)
 {
-    ZSTD_CCtx* cctx = (ZSTD_CCtx*) workspace;
+    ZSTD_CCtx* const cctx = (ZSTD_CCtx*) workspace;
     if (workspaceSize <= sizeof(ZSTD_CCtx)) return NULL;  /* minimum size */
     if ((size_t)workspace & 7) return NULL;  /* must be 8-aligned */
     memset(workspace, 0, workspaceSize);   /* may be a bit generous, could memset be smaller ? */
@@ -97,7 +97,7 @@ ZSTD_CCtx* ZSTD_initStaticCCtx(void *workspace, size_t workspaceSize)
 
     /* entropy space (never moves) */
     if (cctx->workSpaceSize < sizeof(ZSTD_entropyCTables_t)) return NULL;
-    assert(((size_t)cctx->workSpace & 7) == 0);   /* ensure correct alignment */
+    assert(((size_t)cctx->workSpace & (sizeof(void*)-1)) == 0);   /* ensure correct alignment */
     cctx->entropy = (ZSTD_entropyCTables_t*)cctx->workSpace;
 
     return cctx;