# HG changeset patch # User mikael # Date 1114916980 0 # Node ID 5647381a7dfb1315d855549905dd9d279b8bb43c # Parent 9f74832eb4f8d6c7e319852f5d17748138c5b5d6 [/trunk] Changeset 162 by mikael * Fix a severe bug in hbuf_rebuild() diff -r 9f74832eb4f8 -r 5647381a7dfb mcabber/src/hbuf.c --- 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); }