changeset 150:5647381a7dfb

[/trunk] Changeset 162 by mikael * Fix a severe bug in hbuf_rebuild()
author mikael
date Sun, 01 May 2005 03:09:40 +0000
parents 9f74832eb4f8
children b69c0b7a23e3
files mcabber/src/hbuf.c
diffstat 1 files changed, 4 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/hbuf.c	Sat Apr 30 23:06:42 2005 +0000
+++ b/mcabber/src/hbuf.c	Sun May 01 03:09:40 2005 +0000
@@ -159,7 +159,8 @@
   GList *first_elt, *curr_elt, *next_elt;
   hbuf_block *hbuf_b_curr, *hbuf_b_next;
 
-  first_elt = g_list_first(*p_hbuf);
+  // *p_hbuf needs to be the head of the list
+  first_elt = *p_hbuf = g_list_first(*p_hbuf);
 
   // #1 Remove non-persistent blocks (ptr_end should be updated!)
   curr_elt = first_elt;
@@ -174,7 +175,6 @@
     if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) {
       hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end;
       g_list_delete_link(curr_elt, next_elt);
-      next_elt = g_list_next(curr_elt);
     } else 
       curr_elt = next_elt;
   }
@@ -205,15 +205,8 @@
         hbuf_b_curr->ptr_end  = end;
         hbuf_b_curr->flags    = 0;
         hbuf_b_curr->persist.ptr_end_alloc = hbuf_b_prev->persist.ptr_end_alloc;
-        /*
-        // Is there a better way?
-        if (g_list_next(curr_elt))
-          g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr);
-        else
-          *p_hbuf = g_list_append(*p_hbuf, hbuf_b_curr);
-        */
-        // This is OK because insert_before(NULL) <==> append()
-        g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr);
+        // This is OK because insert_before(NULL) == append():
+        *p_hbuf = g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr);
       }
       curr_elt = g_list_next(curr_elt);
     }