* prevent possible NULL dereference, add parameter check
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 5 Nov 2007 15:21:54 +0000 (15:21 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 5 Nov 2007 15:21:54 +0000 (15:21 +0000)
pmo-trunk-r3649

src/modest-text-utils.c
src/modest-text-utils.h
src/widgets/modest-recpt-view.c

index 83de27d..7d2806e 100644 (file)
@@ -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)) {
index e11d702..13e6e1b 100644 (file)
@@ -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:
index 3601c8e..99cb97a 100644 (file)
@@ -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;