From debddb2afee6725855f1b44e3bebbb67769def55 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 8 Aug 2016 23:01:41 +0200 Subject: [PATCH] Fail more gracefully when selecting cells out of range --- src/ui/gui/psppire-data-editor.c | 10 +++++++--- src/ui/gui/psppire-data-store.c | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index c09822e3dc..80bf587695 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -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 { diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 74677259f7..27f5502d3b 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -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; -- 2.30.2