Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/hbuf.c @ 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 | a95e2fc9ea6b |
children | ae0844311710 |
comparison
equal
deleted
inserted
replaced
149:9f74832eb4f8 | 150:5647381a7dfb |
---|---|
157 void hbuf_rebuild(GList **p_hbuf, unsigned int width) | 157 void hbuf_rebuild(GList **p_hbuf, unsigned int width) |
158 { | 158 { |
159 GList *first_elt, *curr_elt, *next_elt; | 159 GList *first_elt, *curr_elt, *next_elt; |
160 hbuf_block *hbuf_b_curr, *hbuf_b_next; | 160 hbuf_block *hbuf_b_curr, *hbuf_b_next; |
161 | 161 |
162 first_elt = g_list_first(*p_hbuf); | 162 // *p_hbuf needs to be the head of the list |
163 first_elt = *p_hbuf = g_list_first(*p_hbuf); | |
163 | 164 |
164 // #1 Remove non-persistent blocks (ptr_end should be updated!) | 165 // #1 Remove non-persistent blocks (ptr_end should be updated!) |
165 curr_elt = first_elt; | 166 curr_elt = first_elt; |
166 while (curr_elt) { | 167 while (curr_elt) { |
167 next_elt = g_list_next(curr_elt); | 168 next_elt = g_list_next(curr_elt); |
172 hbuf_b_next = (hbuf_block*)(next_elt->data); | 173 hbuf_b_next = (hbuf_block*)(next_elt->data); |
173 // Is next line not-persistent? | 174 // Is next line not-persistent? |
174 if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) { | 175 if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) { |
175 hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end; | 176 hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end; |
176 g_list_delete_link(curr_elt, next_elt); | 177 g_list_delete_link(curr_elt, next_elt); |
177 next_elt = g_list_next(curr_elt); | |
178 } else | 178 } else |
179 curr_elt = next_elt; | 179 curr_elt = next_elt; |
180 } | 180 } |
181 // #2 Go back to head and create non-persistent blocks when needed | 181 // #2 Go back to head and create non-persistent blocks when needed |
182 if (width) { | 182 if (width) { |
203 hbuf_b_curr = g_new0(hbuf_block, 1); | 203 hbuf_b_curr = g_new0(hbuf_block, 1); |
204 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end; // == br | 204 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end; // == br |
205 hbuf_b_curr->ptr_end = end; | 205 hbuf_b_curr->ptr_end = end; |
206 hbuf_b_curr->flags = 0; | 206 hbuf_b_curr->flags = 0; |
207 hbuf_b_curr->persist.ptr_end_alloc = hbuf_b_prev->persist.ptr_end_alloc; | 207 hbuf_b_curr->persist.ptr_end_alloc = hbuf_b_prev->persist.ptr_end_alloc; |
208 /* | 208 // This is OK because insert_before(NULL) == append(): |
209 // Is there a better way? | 209 *p_hbuf = g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr); |
210 if (g_list_next(curr_elt)) | |
211 g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr); | |
212 else | |
213 *p_hbuf = g_list_append(*p_hbuf, hbuf_b_curr); | |
214 */ | |
215 // This is OK because insert_before(NULL) <==> append() | |
216 g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr); | |
217 } | 210 } |
218 curr_elt = g_list_next(curr_elt); | 211 curr_elt = g_list_next(curr_elt); |
219 } | 212 } |
220 } | 213 } |
221 } | 214 } |