From: John Darrington Date: Fri, 26 Jan 2007 10:57:15 +0000 (+0000) Subject: Fixed bug which crashed gui if it attempted to enter invalid variable names. X-Git-Tag: v0.6.0~576 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4f8860c584ccc9ffa7d06f711bd051006ba45ef;p=pspp-builds.git Fixed bug which crashed gui if it attempted to enter invalid variable names. --- diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 42025f2d..b32d0677 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -343,13 +343,15 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n) } -void +gboolean psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name) { struct variable *var; g_assert (d); g_assert (PSPPIRE_IS_DICT (d)); + if ( ! var_is_valid_name (name, false)) + return FALSE; if ( idx < dict_get_var_cnt (d->dict)) { @@ -362,6 +364,8 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name) /* new variable */ dict_create_var (d->dict, name, 0); } + + return TRUE; } @@ -735,11 +739,16 @@ tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter, } -void +gboolean psppire_dict_rename_var (PsppireDict *dict, struct variable *v, - const gchar *text) + const gchar *name) { - dict_rename_var (dict->dict, v, text); + if ( ! var_is_valid_name (name, false)) + return FALSE; + + dict_rename_var (dict->dict, v, name); + + return TRUE; } diff --git a/src/ui/gui/psppire-dict.h b/src/ui/gui/psppire-dict.h index f070bfeb..8756dbd8 100644 --- a/src/ui/gui/psppire-dict.h +++ b/src/ui/gui/psppire-dict.h @@ -66,8 +66,8 @@ struct _PsppireDictClass /* -- PsppireDict --- */ GType psppire_dict_get_type (void); -PsppireDict* psppire_dict_new_from_dict (struct dictionary *d); -void psppire_dict_set_name (PsppireDict* s, gint idx, const gchar *name); +PsppireDict* psppire_dict_new_from_dict (struct dictionary *d); +gboolean psppire_dict_set_name (PsppireDict* s, gint idx, const gchar *name); void psppire_dict_delete_var (PsppireDict *s, gint idx); /* Return the number of variables in the dictionary */ @@ -99,7 +99,7 @@ gboolean psppire_dict_check_name (const PsppireDict *dict, gint psppire_dict_get_next_value_idx (const PsppireDict *dict); -void psppire_dict_rename_var (PsppireDict *dict, struct variable *v, +gboolean psppire_dict_rename_var (PsppireDict *dict, struct variable *v, const gchar *text); void psppire_dict_replace_dictionary (PsppireDict *, struct dictionary *); diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index 9ce4f38f..3b3011f0 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -394,8 +394,7 @@ psppire_var_store_set_string (GSheetModel *model, switch (col) { case COL_NAME: - psppire_dict_rename_var (var_store->dict, pv, text); - return TRUE; + return psppire_dict_rename_var (var_store->dict, pv, text); break; case COL_COLUMNS: if ( ! text) return FALSE;