[poppler] 2 commits - glib/demo glib/poppler-form-field.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Thu Mar 24 04:17:23 PDT 2011


 glib/demo/forms.c          |    4 ++--
 glib/poppler-form-field.cc |    4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

New commits:
commit 7b08795a9541e9fa01836b4c7fd63f6fe295ad80
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Thu Mar 24 12:16:07 2011 +0100

    glib: Add g_return macros to make sure index is correct in form field choice methods

diff --git a/glib/poppler-form-field.cc b/glib/poppler-form-field.cc
index 9d4ffbb..55d3bb3 100644
--- a/glib/poppler-form-field.cc
+++ b/glib/poppler-form-field.cc
@@ -540,6 +540,7 @@ poppler_form_field_choice_get_item (PopplerFormField *field,
   GooString *tmp;
   
   g_return_val_if_fail (field->widget->getType () == formChoice, NULL);
+  g_return_val_if_fail (index >= 0 && index < poppler_form_field_choice_get_n_items (field), NULL);
 
   tmp = static_cast<FormWidgetChoice*>(field->widget)->getChoice (index);
   return tmp ? _poppler_goo_string_to_utf8 (tmp) : NULL;
@@ -559,6 +560,7 @@ poppler_form_field_choice_is_item_selected (PopplerFormField *field,
 					    gint              index)
 {
   g_return_val_if_fail (field->widget->getType () == formChoice, FALSE);
+  g_return_val_if_fail (index >= 0 && index < poppler_form_field_choice_get_n_items (field), FALSE);
 
   return static_cast<FormWidgetChoice*>(field->widget)->isSelected (index);
 }
@@ -575,6 +577,7 @@ poppler_form_field_choice_select_item (PopplerFormField *field,
 				       gint              index)
 {
   g_return_if_fail (field->widget->getType () == formChoice);
+  g_return_if_fail (index >= 0 && index < poppler_form_field_choice_get_n_items (field));
 
   static_cast<FormWidgetChoice*>(field->widget)->select (index);
 }
@@ -605,6 +608,7 @@ poppler_form_field_choice_toggle_item (PopplerFormField *field,
 				       gint              index)
 {
   g_return_if_fail (field->widget->getType () == formChoice);
+  g_return_if_fail (index >= 0 && index < poppler_form_field_choice_get_n_items (field));
 
   static_cast<FormWidgetChoice*>(field->widget)->toggle (index);
 }
commit f1102fccd2899bc7f97414b1e2a295c59f03da22
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Thu Mar 24 12:15:30 2011 +0100

    glib-demo: Fix a crash when a choice form field has no items selected

diff --git a/glib/demo/forms.c b/glib/demo/forms.c
index 7836b86..fc9695d 100644
--- a/glib/demo/forms.c
+++ b/glib/demo/forms.c
@@ -202,7 +202,7 @@ pgd_form_field_view_set_field (GtkWidget        *field_view,
 		break;
 	case POPPLER_FORM_FIELD_CHOICE: {
 		gchar *item;
-		gint   selected;
+		gint   selected = -1;
 		
 		enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_FORM_CHOICE_TYPE),
 					       poppler_form_field_choice_get_choice_type (field));
@@ -222,7 +222,7 @@ pgd_form_field_view_set_field (GtkWidget        *field_view,
 
 		pgd_form_field_view_add_choice_items (GTK_TABLE (table), field, &selected, &row);
 
-		if (poppler_form_field_choice_get_n_items (field) > selected) {
+		if (selected >= 0 && poppler_form_field_choice_get_n_items (field) > selected) {
 			item = poppler_form_field_choice_get_item (field, selected);
 			text = g_strdup_printf ("%d (%s)", selected, item);
 			g_free (item);


More information about the poppler mailing list