[gtksourceview/wip/regex-search] SearchContext: fix a bug when match_start or match_end is NULL



commit 43052e69095e6946574d062139b87818c715e01b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Jul 30 20:52:36 2013 +0200

    SearchContext: fix a bug when match_start or match_end is NULL

 gtksourceview/gtksourcesearchcontext.c |   38 ++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 41c1f42..c9b24a8 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -2082,6 +2082,9 @@ smart_forward_search (GtkSourceSearchContext *search,
        GtkSourceSearchSettings *settings = get_settings (search);
        const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
 
+       g_return_val_if_fail (match_start != NULL, FALSE);
+       g_return_val_if_fail (match_end != NULL, FALSE);
+
        if (search_text == NULL)
        {
                return FALSE;
@@ -2172,6 +2175,9 @@ smart_backward_search (GtkSourceSearchContext *search,
        GtkSourceSearchSettings *settings = get_settings (search);
        const gchar *search_text = gtk_source_search_settings_get_search_text (settings);
 
+       g_return_val_if_fail (match_start != NULL, FALSE);
+       g_return_val_if_fail (match_end != NULL, FALSE);
+
        if (search_text == NULL)
        {
                return FALSE;
@@ -2911,6 +2917,8 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
                                   GtkTextIter            *match_start,
                                   GtkTextIter            *match_end)
 {
+       GtkTextIter m_start;
+       GtkTextIter m_end;
        gboolean found;
        GtkSourceSearchSettings *settings;
 
@@ -2924,14 +2932,24 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
 
        settings = get_settings (search);
 
-       found = smart_forward_search (search, iter, match_start, match_end);
+       found = smart_forward_search (search, iter, &m_start, &m_end);
 
        if (!found && gtk_source_search_settings_get_wrap_around (settings))
        {
                GtkTextIter start_iter;
                gtk_text_buffer_get_start_iter (search->priv->buffer, &start_iter);
 
-               found = smart_forward_search (search, &start_iter, match_start, match_end);
+               found = smart_forward_search (search, &start_iter, &m_start, &m_end);
+       }
+
+       if (found && match_start != NULL)
+       {
+               *match_start = m_start;
+       }
+
+       if (found && match_end != NULL)
+       {
+               *match_end = m_end;
        }
 
        return found;
@@ -3054,6 +3072,8 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
                                    GtkTextIter            *match_start,
                                    GtkTextIter            *match_end)
 {
+       GtkTextIter m_start;
+       GtkTextIter m_end;
        gboolean found;
        GtkSourceSearchSettings *settings;
 
@@ -3067,7 +3087,7 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
 
        settings = get_settings (search);
 
-       found = smart_backward_search (search, iter, match_start, match_end);
+       found = smart_backward_search (search, iter, &m_start, &m_end);
 
        if (!found && gtk_source_search_settings_get_wrap_around (settings))
        {
@@ -3075,7 +3095,17 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
 
                gtk_text_buffer_get_end_iter (search->priv->buffer, &end_iter);
 
-               found = smart_backward_search (search, &end_iter, match_start, match_end);
+               found = smart_backward_search (search, &end_iter, &m_start, &m_end);
+       }
+
+       if (found && match_start != NULL)
+       {
+               *match_start = m_start;
+       }
+
+       if (found && match_end != NULL)
+       {
+               *match_end = m_end;
        }
 
        return found;


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