]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: data-stack - t_try_realloc get alloc size right in DEBUG builds
authorPhil Carmody <phil@dovecot.fi>
Mon, 28 Jul 2014 13:45:33 +0000 (16:45 +0300)
committerPhil Carmody <phil@dovecot.fi>
Mon, 28 Jul 2014 13:45:33 +0000 (16:45 +0300)
Also introduce a helper variable for the common expression for readability.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/data-stack.c

index fb5d8999b5d03030ddbd7d3cf3b8a6425822666b..55c28921b6a6a8816bc24a0b38d9431d6e567c8c 100644 (file)
@@ -467,11 +467,15 @@ bool t_try_realloc(void *mem, size_t size)
        after_last_alloc = data_stack_after_last_alloc(current_block);
        if (after_last_alloc - last_alloc_size == mem) {
                /* yeah, see if we have space to grow */
-               size = MEM_ALIGN(size);
-               if (current_block->left >= size - last_alloc_size) {
+               size_t new_alloc_size, alloc_growth;
+
+               new_alloc_size = ALLOC_SIZE(size);
+               alloc_growth = (new_alloc_size - last_alloc_size);
+               if (current_block->left >= alloc_growth) {
                        /* just shrink the available size */
-                       current_block->left -= size - last_alloc_size;
-                       current_frame_block->last_alloc_size[frame_pos] = size;
+                       current_block->left -= alloc_growth;
+                       current_frame_block->last_alloc_size[frame_pos] =
+                               new_alloc_size;
                        return TRUE;
                }
        }