# HG changeset patch # User Mikael Berthe # Date 1163333467 -3600 # Node ID b5bcc223cf512a5aad006f16ea8da8a0c0cfc90a # Parent 54405d09b15ab9393f7d1e6792e123d61fcc0f34 Fix a bug in hbuf_add_line() The first line of a buffer was never wrapped, because "curr_elt" was NULL. This patch also removes the useless variable "hbuf". diff -r 54405d09b15a -r b5bcc223cf51 mcabber/src/hbuf.c --- a/mcabber/src/hbuf.c Sun Nov 12 12:12:38 2006 +0100 +++ b/mcabber/src/hbuf.c Sun Nov 12 13:11:07 2006 +0100 @@ -117,7 +117,6 @@ void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp, guint prefix_flags, guint width) { - GList *hbuf = *p_hbuf; GList *curr_elt; char *line, *end; hbuf_block *hbuf_block_elt; @@ -127,22 +126,21 @@ hbuf_block_elt = g_new0(hbuf_block, 1); hbuf_block_elt->prefix.timestamp = timestamp; hbuf_block_elt->prefix.flags = prefix_flags; - if (!hbuf) { + if (!*p_hbuf) { hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; - *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); } else { hbuf_block *hbuf_b_prev; // Set p_hbuf to the end of the list, to speed up history loading // (or CPU time will be used by g_list_last() for each line) - hbuf = *p_hbuf = g_list_last(*p_hbuf); - hbuf_b_prev = hbuf->data; + *p_hbuf = g_list_last(*p_hbuf); + hbuf_b_prev = (*p_hbuf)->data; hbuf_block_elt->ptr = hbuf_b_prev->ptr_end; hbuf_block_elt->flags = HBB_FLAG_PERSISTENT; hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; - *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); } + *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); if (strlen(text) >= HBB_BLOCKSIZE) { // Too long @@ -162,7 +160,7 @@ hbuf_block_elt->ptr_end = line + strlen(line) + 1; end = hbuf_block_elt->ptr_end; - curr_elt = g_list_last(hbuf); + curr_elt = g_list_last(*p_hbuf); // Wrap lines and handle CRs ('\n') do_wrap(p_hbuf, curr_elt, width);