From d6dde814ca3c9b8b1facec057d99ba45c525a066 Mon Sep 17 00:00:00 2001 From: Bert Burgemeister Date: Tue, 7 Jun 2016 19:15:07 +0200 Subject: [PATCH] Don't core dump on GtkComboBoxText :insert_text with missing arguments --- pipeglade.c | 26 +++++++++++--------------- pipegladetest.sh | 13 +++++++++++++ widget-examples/comboboxtext.ui | 6 ++++++ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/pipeglade.c b/pipeglade.c index 6aba08f..6b20329 100644 --- a/pipeglade.c +++ b/pipeglade.c @@ -1331,24 +1331,20 @@ static void update_combo_box_text(struct ui_data *ud) { GtkComboBoxText *combobox = GTK_COMBO_BOX_TEXT(ud->obj); - char data1[strlen(ud->data) + 1]; char dummy; - int val; + int txt0, pos; - strcpy(data1, ud->data); if (eql(ud->action, "prepend_text")) - gtk_combo_box_text_prepend_text(combobox, data1); + gtk_combo_box_text_prepend_text(combobox, ud->data); else if (eql(ud->action, "append_text")) - gtk_combo_box_text_append_text(combobox, data1); - else if (eql(ud->action, "remove") && sscanf(ud->data, "%d %c", &val, &dummy) == 1) - gtk_combo_box_text_remove(combobox, strtol(data1, NULL, 10)); - else if (eql(ud->action, "insert_text")) { - char *position = strtok(data1, WHITESPACE); - char *text = strtok(NULL, WHITESPACE); - - gtk_combo_box_text_insert_text(combobox, - strtol(position, NULL, 10), text); - } else + gtk_combo_box_text_append_text(combobox, ud->data); + else if (eql(ud->action, "remove") && + sscanf(ud->data, "%d %c", &pos, &dummy) == 1) + gtk_combo_box_text_remove(combobox, pos); + else if (eql(ud->action, "insert_text") && + sscanf(ud->data, "%d %n", &pos, &txt0) == 1) + gtk_combo_box_text_insert_text(combobox, pos, ud->data + txt0); + else ign_cmd(ud->type, ud->cmd); } @@ -2703,7 +2699,7 @@ main_quit(struct ui_data *ud) * Write snapshot of widget in an appropriate format to file */ static void -take_snapshot(struct ui_data *ud) +take_snapshot(struct ui_data *ud) { cairo_surface_t *sur = NULL; cairo_t *cr = NULL; diff --git a/pipegladetest.sh b/pipegladetest.sh index 064b646..3357686 100755 --- a/pipegladetest.sh +++ b/pipegladetest.sh @@ -710,6 +710,14 @@ if test $AUTOMATIC; then "ignoring GtkComboBoxText command \"comboboxtext1:nnn\"" check_error "comboboxtext1:force" \ "ignoring GtkComboBoxText command \"comboboxtext1:force\"" + check_error "comboboxtext1:insert_text" \ + "ignoring GtkComboBoxText command \"comboboxtext1:insert_text\"" + check_error "comboboxtext1:insert_text x y" \ + "ignoring GtkComboBoxText command \"comboboxtext1:insert_text x y\"" + check_error "comboboxtext1:remove" \ + "ignoring GtkComboBoxText command \"comboboxtext1:remove\"" + check_error "comboboxtext1:remove x y" \ + "ignoring GtkComboBoxText command \"comboboxtext1:remove x y\"" # GtkTreeView # check_error "treeview1:nnn" \ @@ -1792,6 +1800,11 @@ if test $AUTOMATIC; then "progressbar1:set_text $BIG_STRING" check 0 "" \ "progressbar1:set_text This Is A Progressbar." + check 3 "" \ + "label1:ping\n button1:ping\n main:ping" \ + "label1:ping" \ + "button1:ping" \ + "main:ping" fi diff --git a/widget-examples/comboboxtext.ui b/widget-examples/comboboxtext.ui index 09a72ee..a8c9b35 100644 --- a/widget-examples/comboboxtext.ui +++ b/widget-examples/comboboxtext.ui @@ -8,10 +8,16 @@ True False + True item one item two + + + False + + -- 2.11.4.GIT