Commit 0d5850e6 authored by David Herrmann's avatar David Herrmann Committed by Kristian Høgsberg
Browse files

wayland-util: return -1 if wl_array_copy() fails

We might have to perform memory allocations in wl_array_copy(), so catch
out-of-memory errors in wl_array_add() and return -1 before changing any
Signed-off-by: default avatarDavid Herrmann <>
parent 66e4aa98
......@@ -132,12 +132,18 @@ wl_array_add(struct wl_array *array, size_t size)
return p;
wl_array_copy(struct wl_array *array, struct wl_array *source)
array->size = 0;
wl_array_add(array, source->size);
if (array->size < source->size) {
if (!wl_array_add(array, source->size - array->size))
return -1;
} else {
array->size = source->size;
memcpy(array->data, source->data, source->size);
return 0;
union map_entry {
......@@ -165,7 +165,7 @@ struct wl_array {
void wl_array_init(struct wl_array *array);
void wl_array_release(struct wl_array *array);
void *wl_array_add(struct wl_array *array, size_t size);
void wl_array_copy(struct wl_array *array, struct wl_array *source);
int wl_array_copy(struct wl_array *array, struct wl_array *source);
typedef int32_t wl_fixed_t;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment