util: set errno in wl_map_insert_at()
authorAleksandr Mezin <mezin.alexander@gmail.com>
Tue, 8 Feb 2022 23:36:11 +0000 (05:36 +0600)
committerSimon Ser <contact@emersion.fr>
Fri, 25 Mar 2022 09:43:53 +0000 (09:43 +0000)
And add errno checks in callers, where it seems to be necessary.

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
src/wayland-client.c
src/wayland-server.c
src/wayland-util.c

index 6b0cf43..a9fb01e 100644 (file)
@@ -485,7 +485,10 @@ wl_proxy_create_for_id(struct wl_proxy *factory,
        proxy->refcount = 1;
        proxy->version = factory->version;
 
-       wl_map_insert_at(&display->objects, 0, id, proxy);
+       if (wl_map_insert_at(&display->objects, 0, id, proxy) == -1) {
+               free(proxy);
+               return NULL;
+       }
 
        return proxy;
 }
index 5edbc9c..9fc337b 100644 (file)
@@ -1843,9 +1843,11 @@ wl_resource_create(struct wl_client *client,
        resource->dispatcher = NULL;
 
        if (wl_map_insert_at(&client->objects, 0, id, resource) < 0) {
-               wl_resource_post_error(client->display_resource,
-                                      WL_DISPLAY_ERROR_INVALID_OBJECT,
-                                      "invalid new id %d", id);
+               if (errno == EINVAL) {
+                       wl_resource_post_error(client->display_resource,
+                                              WL_DISPLAY_ERROR_INVALID_OBJECT,
+                                              "invalid new id %d", id);
+               }
                free(resource);
                return NULL;
        }
@@ -2240,10 +2242,12 @@ wl_client_add_resource(struct wl_client *client,
                                          WL_MAP_ENTRY_LEGACY, resource);
        } else if (wl_map_insert_at(&client->objects, WL_MAP_ENTRY_LEGACY,
                                  resource->object.id, resource) < 0) {
-               wl_resource_post_error(client->display_resource,
-                                      WL_DISPLAY_ERROR_INVALID_OBJECT,
-                                      "invalid new id %d",
-                                      resource->object.id);
+               if (errno == EINVAL) {
+                       wl_resource_post_error(client->display_resource,
+                                              WL_DISPLAY_ERROR_INVALID_OBJECT,
+                                              "invalid new id %d",
+                                              resource->object.id);
+               }
                return 0;
        }
 
index ee74bc1..e82b7d2 100644 (file)
@@ -239,8 +239,10 @@ wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)
        }
 
        count = entries->size / sizeof *start;
-       if (count < i)
+       if (count < i) {
+               errno = EINVAL;
                return -1;
+       }
 
        if (count == i) {
                if (!wl_array_add(entries, sizeof *start))