mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 06:35:58 +01:00
Merge pull request #533 from martinetd/wl_array_add
ENOMEM checks: consistently check wl_array_add return
This commit is contained in:
commit
bb24895a2b
7 changed files with 48 additions and 8 deletions
|
@ -223,7 +223,7 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_
|
|||
if (score > st->score || (score == st->score && replaced < st->replaced)) {
|
||||
st->score = score;
|
||||
st->replaced = replaced;
|
||||
memcpy(st->best, st->res, sizeof st->best[0] * st->num_res);
|
||||
memcpy(st->best, st->res, sizeof(st->best[0]) * st->num_res);
|
||||
|
||||
if (st->score == st->num_objs && st->replaced == 0) {
|
||||
st->exit_early = true;
|
||||
|
|
|
@ -95,7 +95,7 @@ static void handle_global(void *data, struct wl_registry *registry,
|
|||
static struct screenshooter_output *output;
|
||||
|
||||
if (strcmp(interface, "wl_output") == 0) {
|
||||
output = calloc(1, sizeof *output);
|
||||
output = calloc(1, sizeof(*output));
|
||||
output->output = wl_registry_bind(registry, name, &wl_output_interface,
|
||||
1);
|
||||
wl_list_insert(&output_list, &output->link);
|
||||
|
|
|
@ -901,12 +901,15 @@ static void data_source_offer(struct wl_client *client,
|
|||
wl_resource_get_user_data(resource);
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&source->mime_types, sizeof *p);
|
||||
p = wl_array_add(&source->mime_types, sizeof(*p));
|
||||
|
||||
if (p) {
|
||||
*p = strdup(mime_type);
|
||||
}
|
||||
if (!p || !*p){
|
||||
if (p) {
|
||||
source->mime_types.size -= sizeof(*p);
|
||||
}
|
||||
wl_resource_post_no_memory(resource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,6 +127,9 @@ static void source_handle_offer(struct wl_client *client,
|
|||
*p = strdup(mime_type);
|
||||
}
|
||||
if (p == NULL || *p == NULL) {
|
||||
if (p) {
|
||||
source->mime_types.size -= sizeof(*p);
|
||||
}
|
||||
wl_resource_post_no_memory(resource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -876,6 +876,11 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat,
|
|||
wl_array_init(&keys);
|
||||
for (size_t i = 0; i < keyboard->num_keycodes; ++i) {
|
||||
uint32_t *p = wl_array_add(&keys, sizeof(uint32_t));
|
||||
if (!p) {
|
||||
wlr_log(L_ERROR, "Cannot allocate memory, skipping keycode: %d\n",
|
||||
keyboard->keycodes[i]);
|
||||
continue;
|
||||
}
|
||||
*p = keyboard->keycodes[i];
|
||||
}
|
||||
uint32_t serial = wl_display_next_serial(seat->display);
|
||||
|
|
|
@ -922,18 +922,34 @@ static void wlr_xdg_toplevel_v6_send_configure(
|
|||
wl_array_init(&states);
|
||||
if (surface->toplevel_state->pending.maximized) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
|
||||
}
|
||||
if (surface->toplevel_state->pending.fullscreen) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
|
||||
}
|
||||
if (surface->toplevel_state->pending.resizing) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
|
||||
}
|
||||
if (surface->toplevel_state->pending.activated) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
|
||||
}
|
||||
|
||||
|
@ -949,6 +965,11 @@ static void wlr_xdg_toplevel_v6_send_configure(
|
|||
height, &states);
|
||||
|
||||
wl_array_release(&states);
|
||||
return;
|
||||
|
||||
error_out:
|
||||
wl_array_release(&states);
|
||||
wl_resource_post_no_memory(surface->toplevel_state->resource);
|
||||
}
|
||||
|
||||
static void wlr_xdg_surface_send_configure(void *user_data) {
|
||||
|
|
|
@ -55,6 +55,10 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
|
|||
int current = selection->source_data.size;
|
||||
if (selection->source_data.size < incr_chunk_size) {
|
||||
p = wl_array_add(&selection->source_data, incr_chunk_size);
|
||||
if (!p){
|
||||
wlr_log(L_ERROR, "Could not allocate selection source_data");
|
||||
goto error_out;
|
||||
}
|
||||
} else {
|
||||
p = (char *) selection->source_data.data + selection->source_data.size;
|
||||
}
|
||||
|
@ -64,11 +68,7 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
|
|||
int len = read(fd, p, available);
|
||||
if (len == -1) {
|
||||
wlr_log(L_ERROR, "read error from data source: %m");
|
||||
xwm_selection_send_notify(selection, XCB_ATOM_NONE);
|
||||
wl_event_source_remove(selection->property_source);
|
||||
selection->property_source = NULL;
|
||||
close(fd);
|
||||
wl_array_release(&selection->source_data);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
wlr_log(L_DEBUG, "read %d (available %d, mask 0x%x) bytes: \"%.*s\"",
|
||||
|
@ -140,6 +140,14 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
|
|||
}
|
||||
|
||||
return 1;
|
||||
|
||||
error_out:
|
||||
xwm_selection_send_notify(selection, XCB_ATOM_NONE);
|
||||
wl_event_source_remove(selection->property_source);
|
||||
selection->property_source = NULL;
|
||||
close(fd);
|
||||
wl_array_release(&selection->source_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void xwm_selection_source_send(struct wlr_xwm_selection *selection,
|
||||
|
|
Loading…
Reference in a new issue