output: fix segfault when using -m last option

Check output list length before accessing previous or next item to avoid
segfault.
This commit is contained in:
Jonathan GUILLOT 2023-07-27 16:58:29 +02:00 committed by Simon Ser
parent 6f78d9d5b2
commit b1129ca72e

View file

@ -225,13 +225,11 @@ output_destroy(struct cg_output *output)
if (wl_list_empty(&server->outputs)) {
wl_display_terminate(server->wl_display);
} else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST) {
} else if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST && !wl_list_empty(&server->outputs)) {
struct cg_output *prev = wl_container_of(server->outputs.next, prev, link);
if (prev) {
output_enable(prev);
view_position_all(server);
}
}
}
static void
@ -293,12 +291,10 @@ handle_new_output(struct wl_listener *listener, void *data)
}
}
if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST) {
if (server->output_mode == CAGE_MULTI_OUTPUT_MODE_LAST && wl_list_length(&server->outputs) > 1) {
struct cg_output *next = wl_container_of(output->link.next, next, link);
if (next) {
output_disable(next);
}
}
if (!wlr_xcursor_manager_load(server->seat->xcursor_manager, wlr_output->scale)) {
wlr_log(WLR_ERROR, "Cannot load XCursor theme for output '%s' with scale %f", wlr_output->name,