[gtksourceview] SpaceDrawer: avoid a potential infinite loop



commit d461b1b45d1aeb81416d6b7a650fc29573dd64c5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Aug 15 22:49:59 2016 +0200

    SpaceDrawer: avoid a potential infinite loop
    
    This maybe fixes:
    https://bugzilla.gnome.org/show_bug.cgi?id=769901

 gtksourceview/gtksourcespacedrawer.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index 2d165bf..94f121f 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -668,21 +668,32 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
 
                if (gtk_text_iter_compare (&iter, &line_end) > 0)
                {
+                       GtkTextIter next_iter = iter;
+
                        /* Move to the first iter in the exposed area of the
                         * next line.
                         */
-                       if (!gtk_text_iter_starts_line (&iter))
+                       if (!gtk_text_iter_starts_line (&next_iter))
                        {
-                               gtk_text_iter_forward_line (&iter);
+                               gtk_text_iter_forward_line (&next_iter);
                        }
 
-                       gtk_text_view_get_line_yrange (text_view, &iter, &ly, NULL);
-                       gtk_text_view_get_iter_at_location (text_view, &iter, min_x, ly);
+                       gtk_text_view_get_line_yrange (text_view, &next_iter, &ly, NULL);
+                       gtk_text_view_get_iter_at_location (text_view, &next_iter, min_x, ly);
 
                        /* Move back one char otherwise tabs may not be redrawn. */
-                       if (!gtk_text_iter_starts_line (&iter))
+                       if (!gtk_text_iter_starts_line (&next_iter))
+                       {
+                               gtk_text_iter_backward_char (&next_iter);
+                       }
+
+                       /* Ensure that we have actually advanced, since the
+                        * above backward_char() is dangerous and can lead to
+                        * infinite loops.
+                        */
+                       if (gtk_text_iter_compare (&next_iter, &iter) > 0)
                        {
-                               gtk_text_iter_backward_char (&iter);
+                               iter = next_iter;
                        }
 
                        _gtk_source_iter_get_leading_spaces_end_boundary (&iter, &leading_end);


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