Fix bug in array growth implementation
With this, test/object is now passing. Yay!
This commit is contained in:
parent
16123e1070
commit
5a5030366e
|
@ -294,30 +294,28 @@ struct hb_static_array_t {
|
||||||
}
|
}
|
||||||
if (likely (len < allocated))
|
if (likely (len < allocated))
|
||||||
return &array[len++];
|
return &array[len++];
|
||||||
|
|
||||||
/* Need to reallocate */
|
/* Need to reallocate */
|
||||||
unsigned int new_allocated = allocated + (allocated >> 1) + 8;
|
unsigned int new_allocated = allocated + (allocated >> 1) + 8;
|
||||||
Type *new_array;
|
Type *new_array = NULL;
|
||||||
|
|
||||||
if (array == static_array) {
|
if (array == static_array) {
|
||||||
new_array = (Type *) calloc (new_allocated, sizeof (Type));
|
new_array = (Type *) calloc (new_allocated, sizeof (Type));
|
||||||
if (new_array) {
|
if (new_array)
|
||||||
memcpy (new_array, array, len * sizeof (Type));
|
memcpy (new_array, array, len * sizeof (Type));
|
||||||
array = new_array;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type));
|
bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type));
|
||||||
if (unlikely (overflows))
|
if (likely (!overflows)) {
|
||||||
new_array = NULL;
|
|
||||||
else
|
|
||||||
new_array = (Type *) realloc (array, new_allocated * sizeof (Type));
|
new_array = (Type *) realloc (array, new_allocated * sizeof (Type));
|
||||||
if (new_array) {
|
|
||||||
free (array);
|
|
||||||
array = new_array;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((len < allocated))
|
|
||||||
return &array[len++];
|
if (unlikely (!new_array))
|
||||||
else
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
array = new_array;
|
||||||
|
allocated = new_allocated;
|
||||||
|
return &array[len++];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void pop (void)
|
inline void pop (void)
|
||||||
|
|
Loading…
Reference in New Issue