From a80b3deaaeee42e48cc3c349f377cae657bfd543 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 5 Nov 2007 15:21:54 +0000 Subject: [PATCH] * prevent possible NULL dereference, add parameter check pmo-trunk-r3649 --- src/modest-text-utils.c | 12 ++++++++---- src/modest-text-utils.h | 8 ++++---- src/widgets/modest-recpt-view.c | 31 ++++++++++++++++--------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 83de27d..7d2806e 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -524,9 +524,9 @@ modest_text_utils_split_addresses_list (const gchar *addresses) void modest_text_utils_address_range_at_position (const gchar *recipients_list, - gint position, - gint *start, - gint *end) + guint position, + guint *start, + guint *end) { gchar *current = NULL; gint range_start = 0; @@ -534,8 +534,12 @@ modest_text_utils_address_range_at_position (const gchar *recipients_list, gint index; gboolean is_quoted = FALSE; + g_return_if_fail (recipients_list); + g_return_if_fail (position < g_utf8_strlen(recipients_list, -1)); + index = 0; - for (current = (gchar *) recipients_list; *current != '\0'; current = g_utf8_find_next_char (current, NULL)) { + for (current = (gchar *) recipients_list; *current != '\0'; + current = g_utf8_find_next_char (current, NULL)) { gunichar c = g_utf8_get_char (current); if ((c == ',') && (!is_quoted)) { diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index e11d702..13e6e1b 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -142,7 +142,7 @@ gchar* modest_text_utils_remove_address (const gchar *address_list, /** * modest_text_utils_address_range_at_position: - * @address_list: utf8 string containing a list of addresses + * @address_list: non-NULL utf8 string containing a list of addresses * @position: a gint * @start: a gint pointer * @end: a gint pointer @@ -153,9 +153,9 @@ gchar* modest_text_utils_remove_address (const gchar *address_list, * @end */ void modest_text_utils_address_range_at_position (const gchar *recipients_list, - gint position, - gint *start, - gint *end); + guint position, + guint *start, + guint *end); /** * modest_text_utils_hyperlinkify_begin: diff --git a/src/widgets/modest-recpt-view.c b/src/widgets/modest-recpt-view.c index 3601c8e..99cb97a 100644 --- a/src/widgets/modest-recpt-view.c +++ b/src/widgets/modest-recpt-view.c @@ -158,23 +158,24 @@ button_release_event (GtkWidget *widget, gtk_text_buffer_get_end_iter (buffer, &end_iter); text = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE); - modest_text_utils_address_range_at_position (text, - index, - &selection_start, &selection_end); - /* TODO: now gtk label tries to select more than the label as usual, - * and we force it to recover the selected region for the defined area. - * It should be fixed (maybe preventing gtklabel to manage selections - * in parallel with us - */ - gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, selection_start); - gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, selection_end); - gtk_text_buffer_select_range (buffer, &start_iter, &end_iter); - - if (text) + /* text will not be NULL, but source code checkers should be satisfied */ + if (text) { + modest_text_utils_address_range_at_position (text, + index, + &selection_start, &selection_end); + /* TODO: now gtk label tries to select more than the label as usual, + * and we force it to recover the selected region for the defined area. + * It should be fixed (maybe preventing gtklabel to manage selections + * in parallel with us + */ + gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, selection_start); + gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, selection_end); + gtk_text_buffer_select_range (buffer, &start_iter, &end_iter); + g_free (text); - + } } - + if (selected) { gchar *selection; -- 1.7.9.5