Do not allow value labels dialog to enter a label for an invalid value.
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 19 Apr 2017 16:48:51 +0000 (18:48 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 19 Apr 2017 16:50:22 +0000 (18:50 +0200)
Fixes bug #45429

src/data/data-in.c
src/ui/gui/helper.c
src/ui/gui/val-labs-dialog.c

index ace167090c57b9f2f2fe97a4d4e96cd80405764d..b0120677b3f7b079d78e7a15c4c17a5073612ac7 100644 (file)
@@ -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,
index d453f2a66593e79548e95e7a8d5b62d478a821d5..72620187abba25bca3be63a4e5484391c0296867 100644 (file)
@@ -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;
 }
index cc1b65494c9fbee387b4c7a934b011c7f8014128..bea5273e00b626ec088284b159eef64c950085e9 100644 (file)
@@ -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 */