Skip to content

Commit

Permalink
Merge pull request #176 from fhilgers/master
Browse files Browse the repository at this point in the history
Fix #146
  • Loading branch information
srdja authored May 29, 2024
2 parents 6b6ec21 + d865684 commit d981423
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cc_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/cc_deque.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,19 +980,22 @@ 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;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
#ifdef ARCH_64
n |= n >> 32;
#endif /* ARCH_64 */
n++;

return n;
Expand Down
7 changes: 5 additions & 2 deletions src/cc_hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,21 @@ 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;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
#ifdef ARCH_64
n |= n >> 32;
#endif /* ARCH_64 */
n++;

return n;
Expand Down
2 changes: 1 addition & 1 deletion src/cc_pqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sized/cc_array_sized.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d981423

Please sign in to comment.