From cfb9446a5ee7156f4b08b34746cc03d194606c99 Mon Sep 17 00:00:00 2001 From: Felix Hilgers <53060619+fhilgers@users.noreply.github.com> Date: Wed, 29 May 2024 14:43:00 +0200 Subject: [PATCH 1/2] Fix upper_pow_two and round_pow_two --- src/cc_deque.c | 7 +++++-- src/cc_hashtable.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cc_deque.c b/src/cc_deque.c index b7e20fe..6d4ad5a 100644 --- a/src/cc_deque.c +++ b/src/cc_deque.c @@ -980,12 +980,12 @@ static INLINE size_t upper_pow_two(size_t n) return MAX_POW_TWO; if (n == 0) - return 2; + return 1; /** * taken from: * http://graphics.stanford.edu/~seander/ - * bithacks.html#RoundUpPowerOf2Float + * bithacks.html#RoundUpPowerOf2 */ n--; n |= n >> 1; @@ -993,6 +993,9 @@ static INLINE size_t upper_pow_two(size_t n) n |= n >> 4; n |= n >> 8; n |= n >> 16; +#ifdef ARCH_64 + n |= n >> 32; +#endif /* ARCH_64 */ n++; return n; diff --git a/src/cc_hashtable.c b/src/cc_hashtable.c index 9c9f648..9d8e63c 100644 --- a/src/cc_hashtable.c +++ b/src/cc_hashtable.c @@ -448,11 +448,11 @@ static INLINE size_t round_pow_two(size_t n) return MAX_POW_TWO; if (n == 0) - return 2; + return 1; /** * taken from: * http://graphics.stanford.edu/~seander/ - * bithacks.html#RoundUpPowerOf2Float + * bithacks.html#RoundUpPowerOf2 */ n--; n |= n >> 1; @@ -460,6 +460,9 @@ static INLINE size_t round_pow_two(size_t n) n |= n >> 4; n |= n >> 8; n |= n >> 16; +#ifdef ARCH_64 + n |= n >> 32; +#endif /* ARCH_64 */ n++; return n; From d8656846b31ddc3386b403df4bcaa5271b99851b Mon Sep 17 00:00:00 2001 From: Felix Hilgers <53060619+fhilgers@users.noreply.github.com> Date: Wed, 29 May 2024 14:43:07 +0200 Subject: [PATCH 2/2] Fix use ar->capacity for ar->mem_alloc --- src/cc_array.c | 2 +- src/cc_pqueue.c | 2 +- src/sized/cc_array_sized.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc_array.c b/src/cc_array.c index 87ea45b..7b48b82 100644 --- a/src/cc_array.c +++ b/src/cc_array.c @@ -853,7 +853,7 @@ static enum cc_stat expand_capacity(CC_Array *ar) else ar->capacity = new_capacity; - void **new_buff = ar->mem_alloc(new_capacity * sizeof(void*)); + void **new_buff = ar->mem_alloc(ar->capacity * sizeof(void*)); if (!new_buff) return CC_ERR_ALLOC; diff --git a/src/cc_pqueue.c b/src/cc_pqueue.c index 1d9c420..fe996b0 100644 --- a/src/cc_pqueue.c +++ b/src/cc_pqueue.c @@ -193,7 +193,7 @@ static enum cc_stat expand_capacity(CC_PQueue *pq) else pq->capacity = new_capacity; - void **new_buff = pq->mem_alloc(new_capacity * sizeof(void*)); + void **new_buff = pq->mem_alloc(pq->capacity * sizeof(void*)); if (!new_buff) return CC_ERR_ALLOC; diff --git a/src/sized/cc_array_sized.c b/src/sized/cc_array_sized.c index 6edc684..8490a88 100644 --- a/src/sized/cc_array_sized.c +++ b/src/sized/cc_array_sized.c @@ -809,7 +809,7 @@ static enum cc_stat expand_capacity(CC_ArraySized *ar) } else { ar->capacity = new_capacity; } - uint8_t *new_buff = ar->mem_alloc(new_capacity * ar->data_length); + uint8_t *new_buff = ar->mem_alloc(ar->capacity * ar->data_length); if (!new_buff) { return CC_ERR_ALLOC;