[gtksourceview/gnome-3-24] regex: fix offset behavior



commit 259acf6b04ce9b48a3819e89748eb731836ab1aa
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 11 20:26:24 2018 -0800

    regex: fix offset behavior
    
    When handling the -1 possibility, the branch that was be taken was also
    changed. That caused some warnings with the underlying system. Instead,
    we should force the start position at 0 (rather than str-1).

 gtksourceview/gtksourceregex.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourceregex.c b/gtksourceview/gtksourceregex.c
index 7d53ceaf..4304a6af 100644
--- a/gtksourceview/gtksourceregex.c
+++ b/gtksourceview/gtksourceregex.c
@@ -335,8 +335,7 @@ _gtk_source_regex_fetch_pos (GtkSourceRegex *regex,
        g_assert (regex->resolved);
 
        /* g_match_info_fetch_pos() can return TRUE with start_pos/end_pos set to -1 */
-       if (!g_match_info_fetch_pos (regex->u.regex.match, num, &byte_start_pos, &byte_end_pos) ||
-           byte_start_pos == -1 || byte_end_pos == 1)
+       if (!g_match_info_fetch_pos (regex->u.regex.match, num, &byte_start_pos, &byte_end_pos))
        {
                if (start_pos != NULL)
                        *start_pos = -1;
@@ -346,9 +345,9 @@ _gtk_source_regex_fetch_pos (GtkSourceRegex *regex,
        else
        {
                if (start_pos != NULL)
-                       *start_pos = g_utf8_pointer_to_offset (text, text + byte_start_pos);
+                       *start_pos = g_utf8_pointer_to_offset (text, text + MAX (0, byte_start_pos));
                if (end_pos != NULL)
-                       *end_pos = g_utf8_pointer_to_offset (text, text + byte_end_pos);
+                       *end_pos = g_utf8_pointer_to_offset (text, text + MAX (0, byte_end_pos));
        }
 }
 


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