summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-09-23 10:26:15 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-09-23 10:26:15 -0400
commit7910074a8cc73f6ac5b8345851ff16058e60272b (patch)
tree598385d155e067fdda2bc1c3ea0348eab526837b /util
parent215cb46e3c2b3978d593d17fe47a78b6e6a08082 (diff)
fixed block arr
Diffstat (limited to 'util')
-rw-r--r--util/blockarr.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/util/blockarr.c b/util/blockarr.c
index bdbffd3..38bbf1b 100644
--- a/util/blockarr.c
+++ b/util/blockarr.c
@@ -30,18 +30,19 @@ static void block_arr_create(BlockArr *arr, int lg_block_sz, size_t item_sz) {
static void *block_arr_add(BlockArr *arr) {
ArrBlock *last_block;
last_block = arr_last(&arr->blocks);
-
if (arr->blocks.data == NULL ||
(unsigned long)last_block->n >= (1UL << arr->lg_block_sz)) {
ArrBlock *block;
/* no blocks yet / ran out of blocks*/
block = arr_add(&arr->blocks);
- block->data = err_malloc(arr->item_sz << arr->lg_block_sz);
block->n = 1;
+ size_t bytes = arr->item_sz << arr->lg_block_sz;
+ block->data = err_malloc(bytes);
block->last = block->data;
return block->data;
} else {
last_block->last = (char*)last_block->last + arr->item_sz;
+ last_block->n++;
return last_block->last;
}
}