workspaces: don't segfault on invalid move_surface_to_workspace request

Also fixes the off-by-one in toytoolkit that exposed the issue.
This commit is contained in:
Philipp Brüschweiler
2012-09-01 16:03:05 +02:00
committed by Kristian Høgsberg
parent 8538b22ff4
commit 067abf67cd
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -1704,7 +1704,7 @@ frame_menu_func(struct window *window, int index, void *data)
break; break;
case 3: /* move to workspace below */ case 3: /* move to workspace below */
display = window->display; display = window->display;
if (display->workspace < display->workspace_count) if (display->workspace < display->workspace_count - 1)
workspace_manager_move_surface(display->workspace_manager, workspace_manager_move_surface(display->workspace_manager,
window->surface, window->surface,
display->workspace + 1); display->workspace + 1);
+4
View File
@@ -548,6 +548,7 @@ static struct workspace *
get_workspace(struct desktop_shell *shell, unsigned int index) get_workspace(struct desktop_shell *shell, unsigned int index)
{ {
struct workspace **pws = shell->workspaces.array.data; struct workspace **pws = shell->workspaces.array.data;
assert(index < shell->workspaces.num);
pws += index; pws += index;
return *pws; return *pws;
} }
@@ -849,6 +850,9 @@ move_surface_to_workspace(struct desktop_shell *shell,
if (workspace == shell->workspaces.current) if (workspace == shell->workspaces.current)
return; return;
if (workspace >= shell->workspaces.num)
workspace = shell->workspaces.num - 1;
from = get_current_workspace(shell); from = get_current_workspace(shell);
to = get_workspace(shell, workspace); to = get_workspace(shell, workspace);