[gtk+/gtk-style-context: 134/347] GtkStyleContext: ensure class lookup return the correct insertion position if not found.



commit 03514278bb2a206f158197fcea8750dc5efdb414
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 2 13:50:17 2010 +0200

    GtkStyleContext: ensure class lookup return the correct insertion position if not found.

 gtk/gtkstylecontext.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index c1ec55d..b58612d 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -646,7 +646,7 @@ style_class_find (GArray *array,
                   GQuark  class_quark,
                   guint  *position)
 {
-  guint min, max, mid;
+  gint min, max, mid;
   gboolean found = FALSE;
 
   if (position)
@@ -668,11 +668,14 @@ style_class_find (GArray *array,
       if (class_quark == item)
         found = TRUE;
       else if (class_quark > item)
-        min = mid + 1;
+        min = mid = mid + 1;
       else
-        max = mid - 1;
+        max = mid = mid - 1;
     }
-  while (!found && min < max);
+  while (!found && min <= max);
+
+  if (mid < 0)
+    mid = 0;
 
   if (position)
     *position = mid;
@@ -685,7 +688,7 @@ child_style_class_find (GArray *array,
                         GQuark  class_quark,
                         guint  *position)
 {
-  guint min, max, mid;
+  gint min, max, mid;
   gboolean found = FALSE;
 
   if (position)
@@ -707,11 +710,14 @@ child_style_class_find (GArray *array,
       if (child_class->class_quark == class_quark)
         found = TRUE;
       else if (child_class->class_quark > class_quark)
-        min = mid + 1;
+        min = mid = mid + 1;
       else
-        max = mid - 1;
+        max = mid = mid - 1;
     }
-  while (!found && min < max);
+  while (!found && min <= max);
+
+  if (mid < 0)
+    mid = 0;
 
   if (position)
     *position = mid;



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