]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added alignment test
authorYann Collet <cyan@fb.com>
Thu, 2 Dec 2021 01:16:36 +0000 (17:16 -0800)
committerYann Collet <cyan@fb.com>
Thu, 2 Dec 2021 01:16:36 +0000 (17:16 -0800)
and fix an incorrect alignment check in cwksp which was failing on m68k

lib/common/mem.h
lib/compress/zstd_cwksp.h

index 1c61b7e52f1b61085e96a3762aeb12cc9bb00968..4803897cf80dcd9ea08f103e6b94c5b4ce7bf73b 100644 (file)
@@ -80,6 +80,26 @@ extern "C" {
 #endif
 
 
+/*-**************************************************************
+*  Alignment check
+*****************************************************************/
+
+/* C11 support */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+
+#include <stdalign.h>
+# 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
 *****************************************************************/
index 7ba90262d522a4f2cdea95a55bd20a067b706e93..305667606d692c430a94086730c57d0d5a987826 100644 (file)
@@ -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) {