From 12e1855bba344bd78ea6466a47b1705e7e46a000 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Tue, 7 Aug 2007 21:52:29 +0000 Subject: [PATCH] Do not assume that text is null-terminated as pointed out by Christopher 2007-08-07 Johan Dahlin * gtk/gtkbuilderparser.c (text): * gtk/gtkcelllayout.c (attributes_text_element): * gtk/gtkliststore.c (list_store_text): Do not assume that text is null-terminated as pointed out by Christopher Fergeau svn path=/trunk/; revision=18592 --- ChangeLog | 6 ++++++ gtk/gtkbuilderparser.c | 14 ++++++++++---- gtk/gtkcelllayout.c | 12 ++++++++---- gtk/gtkliststore.c | 5 ++++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27c57a874b..327018863b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-08-07 Johan Dahlin + * gtk/gtkbuilderparser.c (text): + * gtk/gtkcelllayout.c (attributes_text_element): + * gtk/gtkliststore.c (list_store_text): + Do not assume that text is null-terminated as pointed out by + Christopher Fergeau + * gtk/gtkbuilderparser.c (text): Use g_strdup on the translated string instead of g_strndup() + the length of the untranslated string. (#461945, Claude Paroz) diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c index 9ca1889b47..23d45db479 100644 --- a/gtk/gtkbuilderparser.c +++ b/gtk/gtkbuilderparser.c @@ -908,14 +908,20 @@ text (GMarkupParseContext *context, { PropertyInfo *prop_info = (PropertyInfo*)info; + /* text is not guaranteed to be null-terminated */ + char *string = g_strndup (text, text_len); + if (prop_info->translatable && text_len) { - if (prop_info->context) - text = dpgettext (data->domain, prop_info->context, text); + if (prop_info->context) + text = dpgettext (data->domain, prop_info->context, string); else - text = dgettext (data->domain, text); + text = dgettext (data->domain, string); + + g_free (string); + string = g_strdup (text); } - prop_info->data = g_strdup (text); + prop_info->data = string; } } diff --git a/gtk/gtkcelllayout.c b/gtk/gtkcelllayout.c index 970ec954df..a9b1c6f6c0 100644 --- a/gtk/gtkcelllayout.c +++ b/gtk/gtkcelllayout.c @@ -349,21 +349,25 @@ attributes_text_element (GMarkupParseContext *context, AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data; glong l; gchar *endptr; - + gchar *string; + if (!parser_data->attr_name) return; errno = 0; - l = strtol (text, &endptr, 0); - if (errno || endptr == text) + string = g_strndup (text, text_len); + l = strtol (string, &endptr, 0); + if (errno || endptr == string) { g_set_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_VALUE, "Could not parse integer `%s'", - text); + string); + g_free (string); return; } + g_free (string); gtk_cell_layout_add_attribute (parser_data->cell_layout, parser_data->renderer, diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c index 5694f76400..617a5fedd8 100644 --- a/gtk/gtkliststore.c +++ b/gtk/gtkliststore.c @@ -2188,15 +2188,17 @@ list_store_text (GMarkupParseContext *context, SubParserData *data = (SubParserData*)user_data; gint i; GError *tmp_error = NULL; + gchar *string; if (!data->is_data) return; i = data->row_column - 1; + string = g_strndup (text, text_len); if (!gtk_builder_value_from_string_type (data->builder, data->column_types[i], - text, + string, &data->values[i], &tmp_error)) { @@ -2208,6 +2210,7 @@ list_store_text (GMarkupParseContext *context, tmp_error->message); g_error_free (tmp_error); } + g_free (string); } static const GMarkupParser list_store_parser =