]> git.sur5r.net Git - openldap/commitdiff
ITS#6437: Fix alignment after slap_sl_realloc().
authorHallvard Furuseth <hallvard@openldap.org>
Sat, 2 Jan 2010 21:05:11 +0000 (21:05 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Thu, 3 Nov 2011 22:00:02 +0000 (15:00 -0700)
Also use -Align instead of ~pad: Valid also for non-twos complement.

servers/slapd/sl_malloc.c

index 6ed639520bc29cc8c8a18f5e51c6dc3c531c08e2..a3159b2434e2739a9f67f79d0f728d83d9745ad1 100644 (file)
@@ -129,8 +129,7 @@ slap_sl_mem_create(
                return sh;
 
        /* round up to doubleword boundary */
-       size += pad;
-       size &= ~pad;
+       size = (size + Align-1) & -Align;
 
        if (!sh) {
                        sh = ch_malloc(sizeof(struct slab_heap));
@@ -243,8 +242,7 @@ slap_sl_malloc(
        }
 
        /* round up to doubleword boundary, plus space for len at head and tail */
-       size += 2*sizeof(ber_len_t) + pad;
-       size &= ~pad;
+       size = (size + 2*sizeof(ber_len_t) + Align-1) & -Align;
 
        if (sh->sh_stack) {
                if ((char *)sh->sh_last + size >= (char *)sh->sh_end) {
@@ -370,9 +368,8 @@ slap_sl_realloc(void *ptr, ber_len_t size, void *ctx)
        }
 
        if (sh->sh_stack) {
-               /* round up to doubleword boundary */
-               size += pad + sizeof( ber_len_t );
-               size &= ~pad;
+               /* Round up to doubleword boundary, add room for head */
+               size = ((size + Align-1) & -Align) + sizeof( ber_len_t );
 
                p--;