util: set errno in wl_map_reserve_new()

And also fix wl_connection_demarshal() to pass through that errno.

Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
This commit is contained in:
Aleksandr Mezin 2022-02-09 04:10:42 +06:00 committed by Simon Ser
parent ae263cca3e
commit 03e8a1f84b
2 changed files with 17 additions and 7 deletions

View file

@ -810,10 +810,12 @@ wl_connection_demarshal(struct wl_connection *connection,
} }
if (wl_map_reserve_new(objects, id) < 0) { if (wl_map_reserve_new(objects, id) < 0) {
wl_log("not a valid new object id (%u), " if (errno == EINVAL) {
"message %s(%s)\n", wl_log("not a valid new object id (%u), "
id, message->name, message->signature); "message %s(%s)\n", id,
errno = EINVAL; message->name,
message->signature);
}
goto err; goto err;
} }

View file

@ -24,6 +24,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -261,13 +262,17 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)
struct wl_array *entries; struct wl_array *entries;
if (i < WL_SERVER_ID_START) { if (i < WL_SERVER_ID_START) {
if (map->side == WL_MAP_CLIENT_SIDE) if (map->side == WL_MAP_CLIENT_SIDE) {
errno = EINVAL;
return -1; return -1;
}
entries = &map->client_entries; entries = &map->client_entries;
} else { } else {
if (map->side == WL_MAP_SERVER_SIDE) if (map->side == WL_MAP_SERVER_SIDE) {
errno = EINVAL;
return -1; return -1;
}
entries = &map->server_entries; entries = &map->server_entries;
i -= WL_SERVER_ID_START; i -= WL_SERVER_ID_START;
@ -275,8 +280,10 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)
count = entries->size / sizeof *start; count = entries->size / sizeof *start;
if (count < i) if (count < i) {
errno = EINVAL;
return -1; return -1;
}
if (count == i) { if (count == i) {
if (!wl_array_add(entries, sizeof *start)) if (!wl_array_add(entries, sizeof *start))
@ -287,6 +294,7 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)
} else { } else {
start = entries->data; start = entries->data;
if (start[i].data != NULL) { if (start[i].data != NULL) {
errno = EINVAL;
return -1; return -1;
} }
} }