]> granicus.if.org Git - re2c/commitdiff
Use correct formula to find the next aligned address.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 8 May 2019 06:35:42 +0000 (07:35 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 8 May 2019 06:35:42 +0000 (07:35 +0100)
The previous formula worked incorrectly for already aligned addresses
(it added alignment to them).

src/util/slab_allocator.h

index 08faaa7ef973532d3fc9f84f2af102cd9be9f2fa..d4ef91bc1c4affd050187dcca8b99bbeddef422e 100644 (file)
@@ -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<size_t>(current_slab_end_ - current_slab_)) {
             // enough space in slab