From cf24d925dc4776dbccc6143d34760da696dd3eb6 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 8 May 2019 07:35:42 +0100 Subject: [PATCH] Use correct formula to find the next aligned address. The previous formula worked incorrectly for already aligned addresses (it added alignment to them). --- src/util/slab_allocator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/slab_allocator.h b/src/util/slab_allocator.h index 08faaa7e..d4ef91bc 100644 --- a/src/util/slab_allocator.h +++ b/src/util/slab_allocator.h @@ -33,8 +33,8 @@ public: { char *result; - // alignment (we assume that malloc aligns depending on size) - size += ALIGN - (size % ALIGN); + // next aligned address (we assume that malloc aligns depending on size) + size = (size + ALIGN - 1) & ~(ALIGN - 1); if (size <= static_cast(current_slab_end_ - current_slab_)) { // enough space in slab -- 2.40.0