From 9c3a8a5a49a6a66ba93596c0a022ae7ffe7fcf37 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Sat, 18 Jun 2011 19:43:13 +0000
Subject: src/llist.c: Use stable insertion algorithm

Ensure the relative order of elements with equal keys is maintained when
inserting into a sorted list.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
---
 src/llist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/llist.c b/src/llist.c
index b1c2df7..eeded6b 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -162,7 +162,7 @@ llist_add_sorted (llist_t *l, void *data, llist_fn_cmp_t fn_cmp)
 
       if (!l->head)
         l->head = o;
-      else if (fn_cmp(o->data, l->head->data) <= 0)
+      else if (fn_cmp(o->data, l->head->data) < 0)
         {
           o->next = l->head;
           l->head = o;
@@ -170,7 +170,7 @@ llist_add_sorted (llist_t *l, void *data, llist_fn_cmp_t fn_cmp)
       else
         {
           i = l->head;
-          while (i->next && fn_cmp(o->data, i->next->data) > 0)
+          while (i->next && fn_cmp(o->data, i->next->data) >= 0)
             i = i->next;
           o->next = i->next;
           i->next = o;
-- 
cgit v1.2.3-70-g09d2