summaryrefslogtreecommitdiff
path: root/graphics/dia/patches/0007-grid-object-avoid-crash-on-shrink.patch
blob: 59fe831dda35d9c138041604984883ad42a49f26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From ae8bcaa703197d090c0c746c54289ddcc6bbbbb1 Mon Sep 17 00:00:00 2001
From: Hans Breuer <hans@breuer.org>
Date: Thu, 7 Oct 2010 13:21:16 +0200
Subject: [PATCH 07/24] grid-object: avoid crash on shrink

Fix some confusion about rows/columns using the wrong limits.
Resizing object::connections was too early.
(cherry picked from commit cddd958b71a4075751ab76ac3530ced3c33972ea)
---
 objects/Misc/grid_object.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/objects/Misc/grid_object.c b/objects/Misc/grid_object.c
index 05d1b16..11dca8b 100644
--- a/objects/Misc/grid_object.c
+++ b/objects/Misc/grid_object.c
@@ -460,12 +460,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 */
 
@@ -485,6 +479,13 @@ grid_object_reallocate_cells (Grid_Object* grid_object)
       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. */
 
-- 
1.8.4.4