Index: NEWS
===================================================================
--- NEWS	(revision 16193)
+++ NEWS	(working copy)
@@ -5,6 +5,9 @@
 	* Remove apparently confusing textview in the preference 
 	  dialog [#380080]
 
+Morten:
+	* Fix crash in dependency code for named expressions.  [#498347]
+
 --------------------------------------------------------------------------
 Gnumeric 1.7.90 (rc1)
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16193)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2007-11-20  Morten Welinder  <terra@gnome.org>
+
+	* src/sheet.c (sheet_insert_cols, sheet_insert_rows,
+	sheet_delete_cols, sheet_delete_rows): Initialize reloc_info.pos.
+	* src/dependent.c (dependents_relocate): When handling names, get
+	a list of the names as the hash will change during the process.
+	Fixes #498347.
+
 2007-11-19  Jody Goldberg <jody@gnome.org>
 
 	* configure.in : post release bump to 1.7.91-rc2
Index: src/sheet.c
===================================================================
--- src/sheet.c	(revision 16193)
+++ src/sheet.c	(working copy)
@@ -3984,6 +3984,7 @@
 	reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
 	reloc_info.col_offset = count;
 	reloc_info.row_offset = 0;
+	parse_pos_init_sheet (&reloc_info.pos, sheet);
 
 	combine_undo (pundo, dependents_relocate (&reloc_info));
 
@@ -4038,6 +4039,7 @@
 	reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
 	reloc_info.col_offset = SHEET_MAX_COLS; /* force invalidation */
 	reloc_info.row_offset = 0;
+	parse_pos_init_sheet (&reloc_info.pos, sheet);
 
 	/* 0. Walk cells in deleted cols and ensure arrays aren't divided. */
 	if (sheet_range_splits_array (sheet, &reloc_info.origin, NULL,
@@ -4131,6 +4133,8 @@
 	reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
 	reloc_info.col_offset = 0;
 	reloc_info.row_offset = count;
+	parse_pos_init_sheet (&reloc_info.pos, sheet);
+
 	combine_undo (pundo, dependents_relocate (&reloc_info));
 
 	/* 3. Move the rows to their new location (from last to first) */
@@ -4184,6 +4188,7 @@
 	reloc_info.origin_sheet = reloc_info.target_sheet = sheet;
 	reloc_info.col_offset = 0;
 	reloc_info.row_offset = SHEET_MAX_ROWS; /* force invalidation */
+	parse_pos_init_sheet (&reloc_info.pos, sheet);
 
 	/* 0. Walk cells in deleted rows and ensure arrays aren't divided. */
 	if (sheet_range_splits_array (sheet, &reloc_info.origin, NULL,
Index: src/dependent.c
===================================================================
--- src/dependent.c	(revision 16193)
+++ src/dependent.c	(working copy)
@@ -1900,23 +1900,12 @@
 			}});
 }
 
-struct cb_relocate_name {
-	GOUndo *undo;
-	GnmExprRelocateInfo rinfo;
-};
-
 static void
-cb_relocate_name (GnmNamedExpr *nexpr,
+cb_collect_names (GnmNamedExpr *nexpr,
 		  G_GNUC_UNUSED gpointer value,
-		  struct cb_relocate_name *data)
+		  GSList **l)
 {
-	GnmExprTop const *newtree =
-		gnm_expr_top_relocate (nexpr->texpr, &data->rinfo, TRUE);
-	if (newtree) {
-		GOUndo *u = expr_name_set_expr_undo_new (nexpr);
-		data->undo = go_undo_combine (data->undo, u);
-		expr_name_set_expr (nexpr, newtree);
-	}
+	*l = g_slist_prepend (*l, nexpr);
 }
 
 /**
@@ -2053,19 +2042,24 @@
 
 	case GNM_EXPR_RELOCATE_COLS:
 	case GNM_EXPR_RELOCATE_ROWS: {
-		struct cb_relocate_name data;
-		GHashTable *names =
-			rinfo->origin_sheet->deps->referencing_names;
+		GSList *names = NULL, *l;
 
-		if (!names)
-			break;
-
-		data.undo = u_names;
-		data.rinfo = *rinfo;
-		g_hash_table_foreach (names,
-				      (GHFunc)cb_relocate_name,
-				      &data);
-		u_names = data.undo;
+		if (sheet->deps->referencing_names)
+			g_hash_table_foreach (sheet->deps->referencing_names,
+					      (GHFunc)cb_collect_names,
+					      &names);
+		for (l = names; l; l = l->next) {
+			GnmNamedExpr *nexpr = l->data;
+			GnmExprTop const *newtree =
+				gnm_expr_top_relocate (nexpr->texpr,
+						       rinfo, TRUE);
+			if (newtree) {
+				GOUndo *u = expr_name_set_expr_undo_new (nexpr);
+				u_names = go_undo_combine (u_names, u);
+				expr_name_set_expr (nexpr, newtree);
+			}
+		}
+		g_slist_free (names);
 		break;
 
 	default:
