Fail more gracefully when selecting cells out of range
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 8 Aug 2016 21:01:41 +0000 (23:01 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 8 Aug 2016 21:01:41 +0000 (23:01 +0200)
src/ui/gui/psppire-data-editor.c
src/ui/gui/psppire-data-store.c

index c09822e3dcb2a50a331c5a97bc31ee703031e6a2..80bf587695598398093df776f37dcaa401497188 100644 (file)
@@ -242,6 +242,9 @@ change_data_value (PsppireDataStore *store, gint col, gint row, GValue *value)
 {
   const struct variable *var = psppire_dict_get_variable (store->dict, col);
 
+  if (NULL == var)
+    return;
+
   union value v;
   value_init (&v, var_get_width (var));
   v.f = g_value_get_double (value);
@@ -476,9 +479,10 @@ on_data_selection_change (PsppireDataEditor *de, JmdRange *sel)
     {
       /* A single cell is selected */
       const struct variable *var = psppire_dict_get_variable (de->dict, sel->start_x);
-      
-      ref_cell_text = g_strdup_printf (_("%d : %s"),
-                                      sel->start_y + 1, var_get_name (var));
+
+      if (var)
+       ref_cell_text = g_strdup_printf (_("%d : %s"),
+                                        sel->start_y + 1, var_get_name (var));
     }
   else
     {
index 74677259f72ed65d0ab03744f810681ab82cac7f..27f5502d3be6ad71e94d109e6b6da40b48bc07a1 100644 (file)
@@ -139,6 +139,8 @@ __get_value (GtkTreeModel *tree_model,
   PsppireDataStore *store  = PSPPIRE_DATA_STORE (tree_model);
 
   const struct variable *variable = psppire_dict_get_variable (store->dict, column);
+  if (NULL == variable)
+    return;
 
   if (var_is_numeric (variable))
     g_value_init (value, G_TYPE_DOUBLE);
@@ -168,6 +170,9 @@ __get_type (GtkTreeModel *tree_model,   gint idx)
 
   const struct variable *variable = psppire_dict_get_variable (store->dict, idx);
 
+  if (NULL == variable)
+    return 0;
+
   if (var_is_numeric (variable))
     return G_TYPE_DOUBLE;