Invert the sense of ARENA_SIZE_MASK to be consistent with klibc
authorH. Peter Anvin <hpa@zytor.com>
Thu, 19 Jan 2006 17:02:46 +0000 (09:02 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 19 Jan 2006 17:02:46 +0000 (09:02 -0800)
com32/lib/malloc.c
com32/lib/malloc.h
com32/lib/realloc.c

index 8f6d97d..e7a1cdc 100644 (file)
@@ -105,7 +105,7 @@ void *malloc(size_t size)
     return NULL;
 
   /* Add the obligatory arena header, and round up */
-  size = (size+2*sizeof(struct arena_header)-1) & ~ARENA_SIZE_MASK;
+  size = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK;
 
   for ( fp = __malloc_head.next_free ; fp->a.type != ARENA_TYPE_HEAD ;
        fp = fp->next_free ) {
index 70d0e63..830377d 100644 (file)
@@ -37,10 +37,10 @@ struct arena_header {
 #define ARENA_TYPE_HEAD 2
 #endif
 
-#define ARENA_SIZE_MASK (sizeof(struct arena_header)-1)
+#define ARENA_SIZE_MASK (~(uintptr_t)(sizeof(struct arena_header)-1))
 
-#define ARENA_ALIGN_UP(p)      ((char *)(((uintptr_t)(p) + ARENA_SIZE_MASK) & ~ARENA_SIZE_MASK))
-#define ARENA_ALIGN_DOWN(p)    ((char *)((uintptr_t)(p) & ~ARENA_SIZE_MASK))
+#define ARENA_ALIGN_UP(p)      ((char *)(((uintptr_t)(p) + ~ARENA_SIZE_MASK) & ARENA_SIZE_MASK))
+#define ARENA_ALIGN_DOWN(p)    ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK))
 
 /*
  * This structure should be no more than twice the size of the
index 67a2783..577c200 100644 (file)
@@ -24,7 +24,7 @@ void *realloc(void *ptr, size_t size)
   }
 
   /* Add the obligatory arena header, and round up */
-  size = (size+2*sizeof(struct arena_header)-1) & ~ARENA_SIZE_MASK;
+  size = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK;
 
   ah = (struct free_arena_header *)
     ((struct arena_header *)ptr - 1);