From 387372d4d6321ff20f8dadb76906aa77d815b283 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Tue, 25 Nov 2008 00:44:05 -0200 Subject: [PATCH] Fix some bugs feeding the textview GtkTextIter should not be a pointer and, in case the to or body part of the message is empty, use the empty string. --- chat.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/chat.c b/chat.c index 75fdf85..0255330 100644 --- a/chat.c +++ b/chat.c @@ -36,20 +36,22 @@ static void hc_xmpp_chat (hc_xmpp_t *xmpp, iks *message) { GtkTextBuffer *textbuffer; - GtkTextIter *textiter; + GtkTextIter textiter; char *str; char *from; char *body; str = iks_string (iks_stack (message), message); write (fd, str, strlen (str)); - from = iks_find_attrib (message, "from"); - body = iks_cdata (iks_child (iks_find (message, "body"))); + if ((from = iks_find_attrib (message, "from")) == NULL) + from = ""; + if ((body = iks_cdata (iks_child (iks_find (message, "body")))) == NULL) + body = ""; textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); - gtk_text_buffer_get_end_iter (textbuffer, textiter); - gtk_text_buffer_insert (textbuffer, textiter, from, -1); - gtk_text_buffer_insert (textbuffer, textiter, ": ", -1); - gtk_text_buffer_insert (textbuffer, textiter, body, -1); - gtk_text_buffer_insert (textbuffer, textiter, "\n", -1); + gtk_text_buffer_get_end_iter (textbuffer, &textiter); + gtk_text_buffer_insert (textbuffer, &textiter, from, -1); + gtk_text_buffer_insert (textbuffer, &textiter, ": ", -1); + gtk_text_buffer_insert (textbuffer, &textiter, body, -1); + gtk_text_buffer_insert (textbuffer, &textiter, "\n", -1); } static void -- 2.20.1