From: John Darrington Date: Wed, 19 Apr 2017 16:48:51 +0000 (+0200) Subject: Do not allow value labels dialog to enter a label for an invalid value. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d4424f00e2a81c219dc02b050dea4bf2091e765;p=pspp Do not allow value labels dialog to enter a label for an invalid value. Fixes bug #45429 --- diff --git a/src/data/data-in.c b/src/data/data-in.c index ace167090c..b0120677b3 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -76,7 +76,11 @@ static int hexit_value (int c); Stores the parsed representation in OUTPUT, which the caller must have initialized with the given WIDTH (0 for a numeric field, otherwise the string width). If FORMAT is FMT_A, then OUTPUT_ENCODING must specify the - correct encoding for OUTPUT (normally obtained via dict_get_encoding()). */ + correct encoding for OUTPUT (normally obtained via dict_get_encoding()). + + If successful NULL is the return value. Otherwise a string describing + the problem is returned. The caller must free this string. + */ char * data_in (struct substring input, const char *input_encoding, enum fmt_type format, diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index d453f2a665..72620187ab 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -155,7 +155,14 @@ text_to_value__ (const gchar *text, } value_init (val, width); - free (data_in (ss_cstr (text), UTF8, format->type, val, width, encoding)); + char *err = data_in (ss_cstr (text), UTF8, format->type, val, width, encoding); + + if (err) + { + value_destroy (val, width); + val = NULL; + free (err); + } return val; } diff --git a/src/ui/gui/val-labs-dialog.c b/src/ui/gui/val-labs-dialog.c index cc1b65494c..bea5273e00 100644 --- a/src/ui/gui/val-labs-dialog.c +++ b/src/ui/gui/val-labs-dialog.c @@ -348,17 +348,18 @@ do_change (PsppireValLabsDialog *dialog) union value v; - text_to_value__ (val_text, &dialog->format, dialog->encoding, &v); - - val_labs_replace (dialog->labs, &v, - gtk_entry_get_text (GTK_ENTRY (dialog->label_entry))); + if (text_to_value__ (val_text, &dialog->format, dialog->encoding, &v)) + { + val_labs_replace (dialog->labs, &v, + gtk_entry_get_text (GTK_ENTRY (dialog->label_entry))); - gtk_widget_set_sensitive (dialog->change_button, FALSE); + gtk_widget_set_sensitive (dialog->change_button, FALSE); - repopulate_dialog (dialog); - gtk_widget_grab_focus (dialog->value_entry); + repopulate_dialog (dialog); + gtk_widget_grab_focus (dialog->value_entry); - value_destroy (&v, val_labs_get_width (dialog->labs)); + value_destroy (&v, val_labs_get_width (dialog->labs)); + } } /* Callback which occurs when the "Add" button is clicked */ @@ -371,19 +372,20 @@ on_add (GtkWidget *w, gpointer data) const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry)); - text_to_value__ (text, &dialog->format, dialog->encoding, &v); - - if (val_labs_add (dialog->labs, &v, - gtk_entry_get_text - ( GTK_ENTRY (dialog->label_entry)) ) ) + if (text_to_value__ (text, &dialog->format, dialog->encoding, &v)) { - gtk_widget_set_sensitive (dialog->add_button, FALSE); + if (val_labs_add (dialog->labs, &v, + gtk_entry_get_text + ( GTK_ENTRY (dialog->label_entry)) ) ) + { + gtk_widget_set_sensitive (dialog->add_button, FALSE); - repopulate_dialog (dialog); - gtk_widget_grab_focus (dialog->value_entry); - } + repopulate_dialog (dialog); + gtk_widget_grab_focus (dialog->value_entry); + } - value_destroy (&v, val_labs_get_width (dialog->labs)); + value_destroy (&v, val_labs_get_width (dialog->labs)); + } } /* Callback which occurs when the "Remove" button is clicked */