If we cannot increase the array for new entries, we now return -1 instead
of accessing invalid memory.

Signed-off-by: David Herrmann <[email protected]>
---
 src/wayland-private.h | 2 +-
 src/wayland-util.c    | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/wayland-private.h b/src/wayland-private.h
index 8adee9f..406dd39 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -44,7 +44,7 @@ typedef void (*wl_iterator_func_t)(void *element, void *data);
 
 void wl_map_init(struct wl_map *map);
 void wl_map_release(struct wl_map *map);
-uint32_t wl_map_insert_new(struct wl_map *map, uint32_t side, void *data);
+int32_t wl_map_insert_new(struct wl_map *map, uint32_t side, void *data);
 int wl_map_insert_at(struct wl_map *map, uint32_t i, void *data);
 int wl_map_reserve_new(struct wl_map *map, uint32_t i);
 void wl_map_remove(struct wl_map *map, uint32_t i);
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 158f5a5..0ea6f58 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -164,7 +164,7 @@ wl_map_release(struct wl_map *map)
        wl_array_release(&map->server_entries);
 }
 
-WL_EXPORT uint32_t
+WL_EXPORT int32_t
 wl_map_insert_new(struct wl_map *map, uint32_t side, void *data)
 {
        union map_entry *start, *entry;
@@ -185,6 +185,8 @@ wl_map_insert_new(struct wl_map *map, uint32_t side, void 
*data)
                map->free_list = entry->next;
        } else {
                entry = wl_array_add(entries, sizeof *entry);
+               if (!entry)
+                       return -1;
                start = entries->data;
        }
 
-- 
1.7.12.2

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to