diff --git a/chunk.c b/chunk.c index 9f3d52f..6399a9f 100644 --- a/chunk.c +++ b/chunk.c @@ -102,13 +102,13 @@ unsigned long _dmalloc_alloc_total = 0; * here. Basically we cannot do a alloc for the structure and we'd * like it to be static storage so we allocate an array of them to * make sure we have enough forward pointers, when all we need is - * SKIP_SLOT_SIZE(MAX_SKIP_LEVEL + 1) bytes. + * SKIP_SLOT_SIZE(MAX_SKIP_LEVEL - 1) bytes. */ -static skip_alloc_t skip_free_alloc[MAX_SKIP_LEVEL /* read note ^^ */]; +static skip_alloc_t skip_free_alloc[SKIP_SLOT_COUNT(MAX_SKIP_LEVEL - 1)]; static skip_alloc_t *skip_free_list = skip_free_alloc; /* skip list of all of our allocated blocks sorted by address */ -static skip_alloc_t skip_address_alloc[MAX_SKIP_LEVEL /* read note ^^ */]; +static skip_alloc_t skip_address_alloc[SKIP_SLOT_COUNT(MAX_SKIP_LEVEL - 1)]; static skip_alloc_t *skip_address_list = skip_address_alloc; /* update slots which we use to update the skip lists */ diff --git a/chunk_loc.h b/chunk_loc.h index f9f43a7..1c38a42 100644 --- a/chunk_loc.h +++ b/chunk_loc.h @@ -130,6 +130,9 @@ typedef struct skip_alloc_st { #define SKIP_SLOT_SIZE(next_n) \ (sizeof(skip_alloc_t) + sizeof(skip_alloc_t *) * (next_n)) +#define SKIP_SLOT_COUNT(next_n) \ + DIVUP(SKIP_SLOT_SIZE(next_n), sizeof(skip_alloc_t)) + /* entry block magic numbers */ #define ENTRY_BLOCK_MAGIC1 0xEBEB1111 /* for the eb_magic1 field */ #define ENTRY_BLOCK_MAGIC2 0xEBEB2222 /* for the eb_magic2 field */ diff --git a/dmalloc_loc.h b/dmalloc_loc.h index a3615a6..be1dbeb 100644 --- a/dmalloc_loc.h +++ b/dmalloc_loc.h @@ -70,6 +70,9 @@ #undef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#undef DIVUP +#define DIVUP(a,b) (((a) + (b) - 1) / (b)) + /* * bitflag tools for Variable and a Flag */