pipewire: assert a nonzero array allocation size

If pw_array_ensure_size() is called on an array that has not been initialized
with an extend, assert. Otherwise we get stuck in an infinite loop since
doubling our zero allocation size will never reach "need".
This commit is contained in:
Peter Hutterer 2021-06-03 08:57:04 +10:00
parent 0ba9402d4b
commit 4cb87317a7

View file

@ -117,6 +117,7 @@ static inline int pw_array_ensure_size(struct pw_array *arr, size_t size)
if (SPA_UNLIKELY(alloc < need)) { if (SPA_UNLIKELY(alloc < need)) {
void *data; void *data;
alloc = SPA_MAX(alloc, arr->extend); alloc = SPA_MAX(alloc, arr->extend);
spa_assert(alloc != 0); /* forgot pw_array_init */
while (alloc < need) while (alloc < need)
alloc *= 2; alloc *= 2;
if (SPA_UNLIKELY((data = realloc(arr->data, alloc)) == NULL)) if (SPA_UNLIKELY((data = realloc(arr->data, alloc)) == NULL))