Skip to content

Commit

Permalink
Fix potential null accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashkan Kiani authored and ddevault committed Apr 13, 2019
1 parent e7d6b8e commit 913445e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
90 changes: 47 additions & 43 deletions sway/commands/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,37 +311,39 @@ static bool container_move_in_direction(struct sway_container *container,

while (current) {
list_t *siblings = container_get_siblings(current);
enum sway_container_layout layout = container_parent_layout(current);
int index = list_find(siblings, current);
int desired = index + offs;

// Don't allow containers to move out of their
// fullscreen or floating parent
if (current->fullscreen_mode || container_is_floating(current)) {
return false;
}
if (siblings) {
enum sway_container_layout layout = container_parent_layout(current);
int index = list_find(siblings, current);
int desired = index + offs;

// Don't allow containers to move out of their
// fullscreen or floating parent
if (current->fullscreen_mode || container_is_floating(current)) {
return false;
}

if (is_parallel(layout, move_dir)) {
if (desired == -1 || desired == siblings->length) {
if (current->parent == container->parent) {
current = current->parent;
continue;
} else {
// Reparenting
if (current->parent) {
container_insert_child(current->parent, container,
index + (offs < 0 ? 0 : 1));
if (is_parallel(layout, move_dir)) {
if (desired == -1 || desired == siblings->length) {
if (current->parent == container->parent) {
current = current->parent;
continue;
} else {
workspace_insert_tiling(current->workspace, container,
index + (offs < 0 ? 0 : 1));
// Reparenting
if (current->parent) {
container_insert_child(current->parent, container,
index + (offs < 0 ? 0 : 1));
} else {
workspace_insert_tiling(current->workspace, container,
index + (offs < 0 ? 0 : 1));
}
return true;
}
} else {
// Container can move within its siblings
container_move_to_container_from_direction(container,
siblings->items[desired], move_dir);
return true;
}
} else {
// Container can move within its siblings
container_move_to_container_from_direction(container,
siblings->items[desired], move_dir);
return true;
}
}

Expand All @@ -350,26 +352,28 @@ static bool container_move_in_direction(struct sway_container *container,

// Maybe rejigger the workspace
struct sway_workspace *ws = container->workspace;
if (!is_parallel(ws->layout, move_dir)) {
workspace_rejigger(ws, container, move_dir);
return true;
} else if (ws->layout == L_TABBED || ws->layout == L_STACKED) {
workspace_rejigger(ws, container, move_dir);
return true;
}
if (ws) {
if (!is_parallel(ws->layout, move_dir)) {
workspace_rejigger(ws, container, move_dir);
return true;
} else if (ws->layout == L_TABBED || ws->layout == L_STACKED) {
workspace_rejigger(ws, container, move_dir);
return true;
}

// Try adjacent output
struct sway_output *output =
output_get_in_direction(container->workspace->output, move_dir);
if (output) {
struct sway_workspace *ws = output_get_active_workspace(output);
if (!sway_assert(ws, "Expected output to have a workspace")) {
return false;
// Try adjacent output
struct sway_output *output =
output_get_in_direction(container->workspace->output, move_dir);
if (output) {
struct sway_workspace *ws = output_get_active_workspace(output);
if (!sway_assert(ws, "Expected output to have a workspace")) {
return false;
}
container_move_to_workspace_from_direction(container, ws, move_dir);
return true;
}
container_move_to_workspace_from_direction(container, ws, move_dir);
return true;
sway_log(SWAY_DEBUG, "Hit edge of output, nowhere else to go");
}
sway_log(SWAY_DEBUG, "Hit edge of output, nowhere else to go");
return false;
}

Expand Down
12 changes: 7 additions & 5 deletions sway/input/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,13 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) {
}
if (config->mouse_warping == WARP_OUTPUT) {
struct sway_output *output = node_get_output(focus);
struct wlr_box box;
output_get_box(output, &box);
if (wlr_box_contains_point(&box,
seat->cursor->cursor->x, seat->cursor->cursor->y)) {
return;
if (output) {
struct wlr_box box;
output_get_box(output, &box);
if (wlr_box_contains_point(&box,
seat->cursor->cursor->x, seat->cursor->cursor->y)) {
return;
}
}
}

Expand Down

0 comments on commit 913445e

Please sign in to comment.