tree/workspace: fix crash on dragging container to workspace edge

Problem: when dragging a parent container to the right of its children,
sway crashes, the calculated insertion index could exceed the list
bounds. The move logic would compute an index based on the pre-removal
list state.

Solution: Clamp the insertion index to [0, length].
This commit is contained in:
Furkan Sahin 2026-02-01 21:53:06 -05:00
parent b081eba05d
commit 9d2e7d378f

View file

@ -842,6 +842,8 @@ struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace,
if (config->default_layout != L_NONE) {
con = container_split(con, config->default_layout);
}
if (index < 0) index = 0;
else if (index > workspace->tiling->length) index = workspace->tiling->length;
workspace_insert_tiling_direct(workspace, con, index);
return con;
}