diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-03-17 10:02:26 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-03-17 10:02:26 +0000 |
commit | 959bdb992afe0d2964381255da7f7eab6aa9de61 (patch) | |
tree | 37d5b8594be5d15c91faa9e34525b6938e938650 /src/textview.c | |
parent | 6127a936645cf2d2d4fcdfd1461f4d1f7268a3b7 (diff) |
made every code conversion API allocate new memory.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@180 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src/textview.c')
-rw-r--r-- | src/textview.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/textview.c b/src/textview.c index 64480161..fe30d64e 100644 --- a/src/textview.c +++ b/src/textview.c @@ -1010,7 +1010,7 @@ static void textview_write_line(TextView *textview, const gchar *str, GtkTextView *text = GTK_TEXT_VIEW(textview->text); GtkTextBuffer *buffer; GtkTextIter iter; - gchar buf[BUFFSIZE]; + gchar *buf; gchar *fg_color = NULL; gint quotelevel = -1; gchar quote_tag_str[10]; @@ -1018,10 +1018,12 @@ static void textview_write_line(TextView *textview, const gchar *str, buffer = gtk_text_view_get_buffer(text); gtk_text_buffer_get_end_iter(buffer, &iter); - if (!conv) - strncpy2(buf, str, sizeof(buf)); - else if (conv_convert(conv, buf, sizeof(buf), str) < 0) - conv_utf8todisp(buf, sizeof(buf), str); + if (conv) { + buf = conv_convert(conv, str); + if (!buf) + buf = conv_utf8todisp(str); + } else + buf = g_strdup(str); strcrchomp(buf); //if (prefs_common.conv_mb_alnum) conv_mb_alnum(buf); @@ -1053,15 +1055,17 @@ static void textview_write_line(TextView *textview, const gchar *str, textview_make_clickable_parts(textview, fg_color, "link", buf); else textview_make_clickable_parts(textview, fg_color, NULL, buf); + + g_free(buf); } -void textview_write_link(TextView *textview, const gchar *str, - const gchar *uri, CodeConverter *conv) +static void textview_write_link(TextView *textview, const gchar *str, + const gchar *uri, CodeConverter *conv) { GtkTextView *text = GTK_TEXT_VIEW(textview->text); GtkTextBuffer *buffer; GtkTextIter iter; - gchar buf[BUFFSIZE]; + gchar *buf; gchar *bufp; RemoteURI *r_uri; @@ -1071,15 +1075,19 @@ void textview_write_link(TextView *textview, const gchar *str, buffer = gtk_text_view_get_buffer(text); gtk_text_buffer_get_end_iter(buffer, &iter); - if (!conv) - strncpy2(buf, str, sizeof(buf)); - else if (conv_convert(conv, buf, sizeof(buf), str) < 0) - conv_utf8todisp(buf, sizeof(buf), str); + if (conv) { + buf = conv_convert(conv, str); + if (!buf) + buf = conv_utf8todisp(str); + } else + buf = g_strdup(str); strcrchomp(buf); - for (bufp = buf; isspace(*(guchar *)bufp); bufp++) - gtk_text_buffer_insert(buffer, &iter, bufp, 1); + for (bufp = buf; g_ascii_isspace(*bufp); bufp++) + ; + if (bufp > buf) + gtk_text_buffer_insert(buffer, &iter, buf, bufp - buf); r_uri = g_new(RemoteURI, 1); r_uri->uri = g_strdup(uri); @@ -1089,6 +1097,8 @@ void textview_write_link(TextView *textview, const gchar *str, (buffer, &iter, bufp, -1, "link", NULL); r_uri->end = gtk_text_iter_get_offset(&iter); textview->uri_list = g_slist_append(textview->uri_list, r_uri); + + g_free(buf); } void textview_clear(TextView *textview) |