[gedit/wip/spell-checking] spell: make gedit_spell_utils_is_digit() more robust



commit 5a455dc9425fe637c3b3512415212c9b5238d333
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 11 15:49:00 2015 +0200

    spell: make gedit_spell_utils_is_digit() more robust
    
    Using g_utf8_find_next_char() is safer, it returns NULL when the next
    character isn't found.

 plugins/spell/gedit-spell-utils.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-utils.c b/plugins/spell/gedit-spell-utils.c
index 9d7750f..5071886 100644
--- a/plugins/spell/gedit-spell-utils.c
+++ b/plugins/spell/gedit-spell-utils.c
@@ -26,7 +26,6 @@ gboolean
 gedit_spell_utils_is_digit (const gchar *text,
                            gssize       length)
 {
-       gunichar c;
        const gchar *p;
        const gchar *end;
 
@@ -40,19 +39,16 @@ gedit_spell_utils_is_digit (const gchar *text,
        p = text;
        end = text + length;
 
-       while (p < end)
+       while (p != NULL && *p != '\0')
        {
-               const gchar *next;
-               next = g_utf8_next_char (p);
-
-               c = g_utf8_get_char (p);
+               gunichar c = g_utf8_get_char (p);
 
                if (!g_unichar_isdigit (c) && c != '.' && c != ',')
                {
                        return FALSE;
                }
 
-               p = next;
+               p = g_utf8_find_next_char (p, end);
        }
 
        return TRUE;


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