[gimp/gimp-2-8] app: fix handling of guides and sample points in gimpimage-resize.c



commit 4594388060313cc4384f7c6797ea833dad7aba46
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 10 00:08:14 2014 +0200

    app: fix handling of guides and sample points in gimpimage-resize.c
    
    Don't iterate the lists with for() because the loops can remove items,
    which makes us say g_list_next() on a removed list item. Instead, use
    while() and get the next item before possibly removing the current
    one.
    
    (cherry picked from commit 99ccf7223b1aafdc7bc07b37eb8497ccc2912dab)

 app/core/gimpimage-resize.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c
index 2ed9df7..5731a2e 100644
--- a/app/core/gimpimage-resize.c
+++ b/app/core/gimpimage-resize.c
@@ -184,14 +184,16 @@ gimp_image_resize_with_layers (GimpImage    *image,
   g_list_free (resize_layers);
 
   /*  Reposition or remove all guides  */
-  for (list = gimp_image_get_guides (image);
-       list;
-       list = g_list_next (list))
+  list = gimp_image_get_guides (image);
+
+  while (list)
     {
       GimpGuide *guide        = list->data;
       gboolean   remove_guide = FALSE;
       gint       new_position = gimp_guide_get_position (guide);
 
+      list = g_list_next (list);
+
       switch (gimp_guide_get_orientation (guide))
         {
         case GIMP_ORIENTATION_HORIZONTAL:
@@ -217,15 +219,17 @@ gimp_image_resize_with_layers (GimpImage    *image,
     }
 
   /*  Reposition or remove sample points  */
-  for (list = gimp_image_get_sample_points (image);
-       list;
-       list = g_list_next (list))
+  list = gimp_image_get_sample_points (image);
+
+  while (list)
     {
       GimpSamplePoint *sample_point        = list->data;
       gboolean         remove_sample_point = FALSE;
       gint             new_x               = sample_point->x;
       gint             new_y               = sample_point->y;
 
+      list = g_list_next (list);
+
       new_y += offset_y;
       if ((sample_point->y < 0) || (sample_point->y > new_height))
         remove_sample_point = TRUE;


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