From: Thadeu Lima de Souza Cascardo Date: Tue, 25 Nov 2008 02:44:05 +0000 (-0200) Subject: Fix some bugs feeding the textview X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fchat.git;a=commitdiff_plain;h=387372d4d6321ff20f8dadb76906aa77d815b283 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. --- 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