From: Ulya Trofimovich Date: Wed, 8 May 2019 06:35:42 +0000 (+0100) Subject: Use correct formula to find the next aligned address. X-Git-Tag: 1.2~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf24d925dc4776dbccc6143d34760da696dd3eb6;p=re2c Use correct formula to find the next aligned address. The previous formula worked incorrectly for already aligned addresses (it added alignment to them). --- 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