fix list growing when inintial size is 0
This commit is contained in:
parent
5f3362a929
commit
af7e527ff2
1 changed files with 4 additions and 2 deletions
|
@ -8,7 +8,9 @@
|
|||
|
||||
bool _grow_PtkList(void **data, uint32_t *allocated, size_t element_size) {
|
||||
errno = 0;
|
||||
void *tmp = realloc(*data, (*allocated * 2) * element_size);
|
||||
|
||||
const size_t new_allocated = *allocated == 0 ? 1 : *allocated * 2;
|
||||
void *tmp = realloc(*data, new_allocated * element_size);
|
||||
|
||||
if (errno == ENOMEM || tmp == NULL) {
|
||||
free(*data);
|
||||
|
@ -16,7 +18,7 @@ bool _grow_PtkList(void **data, uint32_t *allocated, size_t element_size) {
|
|||
}
|
||||
*data = tmp;
|
||||
|
||||
*allocated *= 2;
|
||||
*allocated = new_allocated;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue