On Thu, Oct 11, 2012 at 11:37:44PM +0200, David Herrmann wrote: > If we cannot increase the array for new entries, we now return -1 instead > of accessing invalid memory.
We can't change the data type of IDs, it has to stay uint32_t. What we can do instead is do define an invalid ID. Either use 0 (and special cases the initialization case where we insert NULL as ID 0) or use 0xffffffff. Server allocated IDs are in the 0xff000000 - 0xffffffff range, so we do use IDs that would be negative as int32_ts. Kristian > 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 _______________________________________________ wayland-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/wayland-devel
