]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Memory alloc size must be a multiple of alignment for aligned_alloc.
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 7 Jan 2024 01:15:06 +0000 (17:15 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 7 Feb 2024 18:16:28 +0000 (19:16 +0100)
zutil_p.h

index bc6f9698d261ae7d65a8a51d181f4d94a3f03f32..97799f0ce31ef232e508a2f5ed85b25c10e9f1a3 100644 (file)
--- a/zutil_p.h
+++ b/zutil_p.h
@@ -17,6 +17,8 @@
 /* Function to allocate 16 or 64-byte aligned memory */
 static inline void *zng_alloc(size_t size) {
 #ifdef HAVE_ALIGNED_ALLOC
+    /* Size must be a multiple of alignment */
+    size = (size + (64 - 1)) & ~(64 - 1);
     return (void *)aligned_alloc(64, size);  /* Defined in C11 */
 #elif defined(HAVE_POSIX_MEMALIGN)
     void *ptr;