[glib] list store: Fix a parameter check



commit d28639507db2029b8f184a5d93e9d8c28acc1955
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Sep 4 13:55:46 2015 -0400

    list store: Fix a parameter check
    
    Getting this wrong causes build failures.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754582

 glib/gsequence.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/glib/gsequence.c b/glib/gsequence.c
index 76e24e7..75c1f76 100644
--- a/glib/gsequence.c
+++ b/glib/gsequence.c
@@ -139,7 +139,8 @@ static GSequenceNode *node_find_closest  (GSequenceNode            *haystack,
                                           GSequenceNode            *needle,
                                           GSequenceNode            *end,
                                           GSequenceIterCompareFunc  cmp,
-                                          gpointer                  user_data);
+                                          gpointer                  user_data,
+                                          gboolean                  return_match);
 static gint           node_get_length    (GSequenceNode            *node);
 static void           node_free          (GSequenceNode            *node,
                                           GSequence                *seq);
@@ -1079,7 +1080,7 @@ g_sequence_search_iter (GSequence                *seq,
   dummy = g_sequence_append (tmp_seq, data);
 
   node = node_find_closest (seq->end_node, dummy,
-                            seq->end_node, iter_cmp, cmp_data);
+                            seq->end_node, iter_cmp, cmp_data, TRUE);
 
   g_sequence_free (tmp_seq);
 
@@ -1733,7 +1734,8 @@ node_find_closest (GSequenceNode            *haystack,
                    GSequenceNode            *needle,
                    GSequenceNode            *end,
                    GSequenceIterCompareFunc  iter_cmp,
-                   gpointer                  cmp_data)
+                   gpointer                  cmp_data,
+                   gboolean                  return_match)
 {
   GSequenceNode *best;
   gint c;
@@ -1763,10 +1765,12 @@ node_find_closest (GSequenceNode            *haystack,
     }
   while (haystack != NULL);
 
-  /* If the best node is smaller or equal to the data, then move one step
-   * to the right to make sure the best one is strictly bigger than the data
+  /* If the best node is smaller than the data, then move one step
+   * to the right to make sure the best one is strictly bigger than the data.
+   * We do return the last exact match or the node after it, depending on
+   * the return_match argument.
    */
-  if (best != end && c <= 0)
+  if (best != end && (c < 0 || (c == 0 && !return_match)))
     best = node_get_next (best);
 
   return best;
@@ -1988,7 +1992,7 @@ node_insert_sorted (GSequenceNode            *node,
 {
   GSequenceNode *closest;
 
-  closest = node_find_closest (node, new, end, iter_cmp, cmp_data);
+  closest = node_find_closest (node, new, end, iter_cmp, cmp_data, FALSE);
 
   node_unlink (new);
 


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