From aee1051a11c6eb396888660701c7a008c904f86b Mon Sep 17 00:00:00 2001 From: bretello Date: Mon, 17 Jul 2023 19:31:53 +0200 Subject: [PATCH] fix crash when resizing tiled scratchpad windows Splitting and then hiding a scratchpad container results in a segfault. fixes #6693 --- sway/commands/resize.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sway/commands/resize.c b/sway/commands/resize.c index f59e2aeb20..79a8719ab3 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -51,11 +51,13 @@ struct sway_container *container_find_resize_parent(struct sway_container *con, while (con) { list_t *siblings = container_get_siblings(con); - int index = container_sibling_index(con); - if (container_parent_layout(con) == parallel_layout && + if (siblings){ + int index = container_sibling_index(con); + if (container_parent_layout(con) == parallel_layout && siblings->length > 1 && (allow_first || index > 0) && (allow_last || index < siblings->length - 1)) { - return con; + return con; + } } con = con->pending.parent; } @@ -302,8 +304,11 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con, } if (parent) { width->amount = parent->pending.width * width->amount / 100; - } else { + } else if (con->pending.workspace) { width->amount = con->pending.workspace->width * width->amount / 100; + } else { + return cmd_results_new(CMD_FAILURE, + "Cannot resize a tiled container with no parent or workspace"); } width->unit = MOVEMENT_UNIT_PX; } @@ -323,8 +328,11 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con, } if (parent) { height->amount = parent->pending.height * height->amount / 100; - } else { + } else if (con->pending.workspace) { height->amount = con->pending.workspace->height * height->amount / 100; + } else { + return cmd_results_new(CMD_FAILURE, + "Cannot resize a tiled container with no parent or workspace"); } height->unit = MOVEMENT_UNIT_PX; }