[dia] grid-object: avoid crash on shrink
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] grid-object: avoid crash on shrink
- Date: Fri, 8 Oct 2010 18:54:55 +0000 (UTC)
commit cddd958b71a4075751ab76ac3530ced3c33972ea
Author: Hans Breuer <hans breuer org>
Date: Thu Oct 7 13:21:16 2010 +0200
grid-object: avoid crash on shrink
Fix some confusion about rows/columns using the wrong limits.
Resizing object::connections was too early.
objects/Misc/grid_object.c | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/objects/Misc/grid_object.c b/objects/Misc/grid_object.c
index b6dcf9c..e34e63f 100644
--- a/objects/Misc/grid_object.c
+++ b/objects/Misc/grid_object.c
@@ -459,12 +459,6 @@ grid_object_reallocate_cells (Grid_Object* grid_object)
if (old_rows == new_rows && old_cols == new_cols)
return; /* no reallocation necessary */
- /* obj->connections doesn't own the pointers, so just realloc; values
- * will be updated later */
- obj->num_connections = GRID_OBJECT_BASE_CONNECTION_POINTS + new_rows*new_cols;
- obj->connections = (ConnectionPoint **) g_realloc(obj->connections,
- obj->num_connections * sizeof(ConnectionPoint *));
-
/* If either new dimension is smaller, some connpoints will have to
* be disconnected before reallocating */
@@ -478,12 +472,19 @@ grid_object_reallocate_cells (Grid_Object* grid_object)
/* implicit: if (new_cols < old_cols) */
for (i = new_cols; i < old_cols; ++i)
- for (j = 0; j < old_cols && j < new_cols; ++j) /* don't double-delete */
+ for (j = 0; j < old_rows && j < new_rows; ++j) /* don't double-delete */
{
int cell = grid_cell(i, j, old_rows, old_cols);
object_remove_connections_to(&grid_object->cells[cell]);
}
+ /* must be done after disconnecting */
+ /* obj->connections doesn't own the pointers, so just realloc; values
+ * will be updated later */
+ obj->num_connections = GRID_OBJECT_BASE_CONNECTION_POINTS + new_rows*new_cols;
+ obj->connections = (ConnectionPoint **) g_realloc(obj->connections,
+ obj->num_connections * sizeof(ConnectionPoint *));
+
/* Can't use realloc; if grid has different dims, memory lays out
* differently. Must copy by hand. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]