From: Yann Collet Date: Thu, 2 Dec 2021 01:16:36 +0000 (-0800) Subject: added alignment test X-Git-Tag: v1.5.1~1^2~35^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e89e84782058f6785bdb5e5d3a1c7111f55e152d;p=thirdparty%2Fzstd.git added alignment test and fix an incorrect alignment check in cwksp which was failing on m68k --- diff --git a/lib/common/mem.h b/lib/common/mem.h index 1c61b7e52..4803897cf 100644 --- a/lib/common/mem.h +++ b/lib/common/mem.h @@ -80,6 +80,26 @@ extern "C" { #endif +/*-************************************************************** +* Alignment check +*****************************************************************/ + +/* C11 support */ +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) + +#include +# define MEM_ALIGN_COND(T) alignof(T) + +#elif defined(__GNUC__) || defined(_MSC_VER) + +# define MEM_ALIGN_COND(T) __alignof(T) + +#else + +# define MEM_ALIGN_COND(T) 1 /* most likely incorrect, just to pass tests */ + +#endif + /*-************************************************************** * Memory I/O API *****************************************************************/ diff --git a/lib/compress/zstd_cwksp.h b/lib/compress/zstd_cwksp.h index 7ba90262d..305667606 100644 --- a/lib/compress/zstd_cwksp.h +++ b/lib/compress/zstd_cwksp.h @@ -422,8 +422,8 @@ MEM_STATIC void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes) { DEBUGLOG(5, "cwksp: reserving %p object %zd bytes (rounded to %zd), %zd bytes remaining", alloc, bytes, roundedBytes, ZSTD_cwksp_available_space(ws) - roundedBytes); - assert(((size_t)alloc & (sizeof(void*)-1)) == 0); - assert((bytes & (sizeof(void*)-1)) == 0); + assert((size_t)alloc % MEM_ALIGN_COND(void*) == 0); + assert(bytes % MEM_ALIGN_COND(void*) == 0); ZSTD_cwksp_assert_internal_consistency(ws); /* we must be in the first phase, no advance is possible */ if (ws->phase != ZSTD_cwksp_alloc_objects || end > ws->workspaceEnd) {