[gspell] Entry utils: make _gspell_entry_utils_get_words() code more robust



commit c2cbf41d7738180d230015a5c734fee760904187
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Aug 19 14:11:04 2017 +0200

    Entry utils: make _gspell_entry_utils_get_words() code more robust
    
    Do the same as in the previous commit.

 gspell/gspell-entry-utils.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/gspell/gspell-entry-utils.c b/gspell/gspell-entry-utils.c
index 3129ff0..de65c21 100644
--- a/gspell/gspell-entry-utils.c
+++ b/gspell/gspell-entry-utils.c
@@ -96,6 +96,12 @@ _gspell_entry_utils_get_words (GtkEntry *entry)
        g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
 
        text = gtk_entry_get_text (entry);
+
+       if (text == NULL || text[0] == '\0')
+       {
+               return NULL;
+       }
+
        get_pango_log_attrs (entry, &attrs, &n_attrs);
 
        attr_num = 0;
@@ -140,13 +146,10 @@ _gspell_entry_utils_get_words (GtkEntry *entry)
                        word_start_char_pos = attr_num;
                }
 
-               if (cur_text_pos == NULL &&
-                   attr_num != n_attrs - 1)
+               if (attr_num == n_attrs - 1 ||
+                   cur_text_pos == NULL ||
+                   cur_text_pos[0] == '\0')
                {
-                       g_warning ("%s(): problem in loop iteration, attr_num=%d but should be %d.",
-                                  G_STRFUNC,
-                                  attr_num,
-                                  n_attrs - 1);
                        break;
                }
 
@@ -154,6 +157,22 @@ _gspell_entry_utils_get_words (GtkEntry *entry)
                cur_text_pos = g_utf8_find_next_char (cur_text_pos, NULL);
        }
 
+       /* Sanity checks */
+
+       if (attr_num != n_attrs - 1)
+       {
+               g_warning ("%s(): problem in loop iteration, attr_num=%d but should be %d. "
+                          "End of string reached too early.",
+                          G_STRFUNC,
+                          attr_num,
+                          n_attrs - 1);
+       }
+
+       if (cur_text_pos != NULL && cur_text_pos[0] != '\0')
+       {
+               g_warning ("%s(): end of string not reached.", G_STRFUNC);
+       }
+
        g_free (attrs);
        return g_slist_reverse (list);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]