mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 05:08:08 +02:00
gallium/auxiliary: fix util_dynarray_trim to 0 to free the data
This works better and preserves the data != 0 if and only if capacity != 0 invariant.
This commit is contained in:
parent
5f968a64dc
commit
c572619817
1 changed files with 8 additions and 2 deletions
|
|
@ -81,8 +81,14 @@ util_dynarray_grow(struct util_dynarray *buf, int size)
|
|||
static INLINE void
|
||||
util_dynarray_trim(struct util_dynarray *buf)
|
||||
{
|
||||
buf->data = REALLOC(buf->data, buf->capacity, buf->size);
|
||||
buf->capacity = buf->size;
|
||||
if(buf->size) {
|
||||
buf->data = REALLOC(buf->data, buf->capacity, buf->size);
|
||||
buf->capacity = buf->size;
|
||||
} else {
|
||||
FREE(buf->data);
|
||||
buf->data = 0;
|
||||
buf->capacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow((buf), sizeof(type)), &__v, sizeof(type));} while(0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue