summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren gmail com>2007-04-03 19:58:13 +0000
committerElijah Newren <newren@src.gnome.org>2007-04-03 19:58:13 +0000
commit1b04f5e5fb5aae90f3ea96c5b6488d6902d40e93 (patch)
treeb63d865271e8bb54149825d8ba8816a71d8963a9
parented4ef8d0a641d49d542e85e18d4605396ca9c6ab (diff)
downloadmetacity-1b04f5e5fb5aae90f3ea96c5b6488d6902d40e93.tar.gz
Avoid some crashes when dragging windows partially offscreen. Possible (or
2007-04-03 Elijah Newren <newren gmail com> Avoid some crashes when dragging windows partially offscreen. Possible (or at least partial) fix for #353513. * src/edge-resistance.c (apply_edge_resistance): be more careful about calls to find_index_of_edge_near_position() returning possibly invalid indices. Also, add a warning comment to find_index_of_edge_near_position(). svn path=/branches/gnome-2-18/; revision=3148
-rw-r--r--ChangeLog10
-rw-r--r--src/edge-resistance.c11
2 files changed, 21 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 09426663..88958146 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-04-03 Elijah Newren <newren gmail com>
+
+ Avoid some crashes when dragging windows partially offscreen.
+ Possible (or at least partial) fix for #353513.
+
+ * src/edge-resistance.c (apply_edge_resistance): be more careful
+ about calls to find_index_of_edge_near_position() returning
+ possibly invalid indices. Also, add a warning comment to
+ find_index_of_edge_near_position().
+
2007-03-31 Elijah Newren <newren gmail com>
Clean up event mask handling and meta_create_offscreen_window, to
diff --git a/src/edge-resistance.c b/src/edge-resistance.c
index 3db21ab4..a536accc 100644
--- a/src/edge-resistance.c
+++ b/src/edge-resistance.c
@@ -62,6 +62,9 @@ struct MetaEdgeResistanceData
ResistanceDataForAnEdge bottom_data;
};
+/* !WARNING!: this function can return invalid indices (namely, either -1 or
+ * edges->len); this is by design, but you need to remember this.
+ */
static int
find_index_of_edge_near_position (const GArray *edges,
int position,
@@ -330,6 +333,7 @@ apply_edge_resistance (MetaWindow *window,
gboolean keyboard_op)
{
int i, begin, end;
+ int last_edge;
gboolean increasing = new_pos > old_pos;
int increment = increasing ? 1 : -1;
@@ -366,6 +370,13 @@ apply_edge_resistance (MetaWindow *window,
begin = find_index_of_edge_near_position (edges, old_pos, increasing, xdir);
end = find_index_of_edge_near_position (edges, new_pos, !increasing, xdir);
+ /* begin and end can be outside the array index, if the window is partially
+ * off the screen
+ */
+ last_edge = edges->len - 1;
+ begin = CLAMP (begin, 0, last_edge);
+ end = CLAMP (end, 0, last_edge);
+
/* Loop over all these edges we're moving past/to. */
i = begin;
while ((increasing && i <= end) ||