diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/codeconv.c | 288 | ||||
-rw-r--r-- | src/codeconv.h | 12 | ||||
-rw-r--r-- | src/html.c | 13 | ||||
-rw-r--r-- | src/procheader.c | 6 | ||||
-rw-r--r-- | src/rfc2015.c | 7 | ||||
-rw-r--r-- | src/sourcewindow.c | 6 | ||||
-rw-r--r-- | src/textview.c | 38 | ||||
-rw-r--r-- | src/unmime.c | 6 |
8 files changed, 191 insertions, 185 deletions
diff --git a/src/codeconv.c b/src/codeconv.c index 78895f91..263eb679 100644 --- a/src/codeconv.c +++ b/src/codeconv.c @@ -104,36 +104,40 @@ typedef enum state = JIS_AUXKANJI; \ } -static void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf); +static gchar *conv_jistoeuc(const gchar *inbuf); +static gchar *conv_euctojis(const gchar *inbuf); +static gchar *conv_sjistoeuc(const gchar *inbuf); -static void conv_jistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_sjistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_euctoutf8(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_anytoutf8(gchar *outbuf, gint outlen, const gchar *inbuf); +static gchar *conv_jistoutf8(const gchar *inbuf); +static gchar *conv_sjistoutf8(const gchar *inbuf); +static gchar *conv_euctoutf8(const gchar *inbuf); +static gchar *conv_anytoutf8(const gchar *inbuf); -static void conv_utf8toeuc(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_utf8tojis(gchar *outbuf, gint outlen, const gchar *inbuf); +static gchar *conv_utf8toeuc(const gchar *inbuf); +static gchar *conv_utf8tojis(const gchar *inbuf); -static void conv_unreadable_eucjp(gchar *str); +/* static void conv_unreadable_eucjp(gchar *str); */ static void conv_unreadable_8bit(gchar *str); -static void conv_unreadable_latin(gchar *str); +/* static void conv_unreadable_latin(gchar *str); */ -static void conv_jistodisp(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_sjistodisp(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_euctodisp(gchar *outbuf, gint outlen, const gchar *inbuf); +static gchar *conv_jistodisp(const gchar *inbuf); +static gchar *conv_sjistodisp(const gchar *inbuf); +static gchar *conv_euctodisp(const gchar *inbuf); -static void conv_anytodisp(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_ustodisp(gchar *outbuf, gint outlen, const gchar *inbuf); -static void conv_noconv(gchar *outbuf, gint outlen, const gchar *inbuf); +static gchar *conv_anytodisp(const gchar *inbuf); +static gchar *conv_ustodisp(const gchar *inbuf); +static gchar *conv_noconv(const gchar *inbuf); -static void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_jistoeuc(const gchar *inbuf) { + gchar *outbuf; const guchar *in = inbuf; - guchar *out = outbuf; + guchar *out; JISState state = JIS_ASCII; + outbuf = g_malloc(strlen(inbuf) + 1); + out = outbuf; + while (*in != '\0') { if (*in == ESC) { in++; @@ -195,6 +199,8 @@ static void conv_jistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf) } *out = '\0'; + + return outbuf; } #define JIS_HWDAKUTEN 0x5e @@ -263,11 +269,15 @@ static gint conv_jis_hantozen(guchar *outbuf, guchar jis_code, guchar sound_sym) return 1; } -static void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_euctojis(const gchar *inbuf) { + gchar *outbuf; const guchar *in = inbuf; - guchar *out = outbuf; + guchar *out; JISState state = JIS_ASCII; + + outbuf = g_malloc(strlen(inbuf) * 3 + 4); + out = outbuf; while (*in != '\0') { if (isascii(*in)) { @@ -349,12 +359,18 @@ static void conv_euctojis(gchar *outbuf, gint outlen, const gchar *inbuf) K_OUT(); *out = '\0'; + + return outbuf; } -static void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_sjistoeuc(const gchar *inbuf) { + gchar *outbuf; const guchar *in = inbuf; - guchar *out = outbuf; + guchar *out; + + outbuf = g_malloc(strlen(inbuf) * 2 + 1); + out = outbuf; while (*in != '\0') { if (isascii(*in)) { @@ -395,41 +411,41 @@ static void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf) } *out = '\0'; + + return outbuf; } -static void conv_jistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_jistoutf8(const gchar *inbuf) { - gchar *eucstr; + gchar *eucstr, *utf8str; - Xalloca(eucstr, outlen, return); + eucstr = conv_jistoeuc(inbuf); + utf8str = conv_euctoutf8(eucstr); + g_free(eucstr); - conv_jistoeuc(eucstr, outlen, inbuf); - conv_euctoutf8(outbuf, outlen, eucstr); + return utf8str; } -static void conv_sjistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_sjistoutf8(const gchar *inbuf) { - gchar *tmpstr; - - tmpstr = conv_iconv_strdup(inbuf, CS_SHIFT_JIS, CS_UTF_8, NULL); - if (tmpstr) { - strncpy2(outbuf, tmpstr, outlen); - g_free(tmpstr); - } else - strncpy2(outbuf, inbuf, outlen); + gchar *utf8str; + + utf8str = conv_iconv_strdup(inbuf, CS_SHIFT_JIS, CS_UTF_8, NULL); + if (!utf8str) + utf8str = g_strdup(inbuf); + + return utf8str; } -static void conv_euctoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_euctoutf8(const gchar *inbuf) { static iconv_t cd = (iconv_t)-1; static gboolean iconv_ok = TRUE; - gchar *tmpstr; if (cd == (iconv_t)-1) { - if (!iconv_ok) { - strncpy2(outbuf, inbuf, outlen); - return; - } + if (!iconv_ok) + return g_strdup(inbuf); + cd = iconv_open(CS_UTF_8, CS_EUC_JP_MS); if (cd == (iconv_t)-1) { cd = iconv_open(CS_UTF_8, CS_EUC_JP); @@ -437,49 +453,37 @@ static void conv_euctoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) g_warning("conv_euctoutf8(): %s\n", g_strerror(errno)); iconv_ok = FALSE; - strncpy2(outbuf, inbuf, outlen); - return; + return g_strdup(inbuf); } } } - tmpstr = conv_iconv_strdup_with_cd(inbuf, cd, NULL); - if (tmpstr) { - strncpy2(outbuf, tmpstr, outlen); - g_free(tmpstr); - } else - strncpy2(outbuf, inbuf, outlen); + return conv_iconv_strdup_with_cd(inbuf, cd, NULL); } -static void conv_anytoutf8(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_anytoutf8(const gchar *inbuf) { switch (conv_guess_ja_encoding(inbuf)) { case C_ISO_2022_JP: - conv_jistoutf8(outbuf, outlen, inbuf); - break; + return conv_jistoutf8(inbuf); case C_SHIFT_JIS: - conv_sjistoutf8(outbuf, outlen, inbuf); - break; + return conv_sjistoutf8(inbuf); case C_EUC_JP: - conv_euctoutf8(outbuf, outlen, inbuf); - break; + return conv_euctoutf8(inbuf); default: - strncpy2(outbuf, inbuf, outlen); - break; + return g_strdup(inbuf); } } -static void conv_utf8toeuc(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_utf8toeuc(const gchar *inbuf) { static iconv_t cd = (iconv_t)-1; static gboolean iconv_ok = TRUE; - gchar *tmpstr; if (cd == (iconv_t)-1) { - if (!iconv_ok) { - strncpy2(outbuf, inbuf, outlen); - return; - } + if (!iconv_ok) + return g_strdup(inbuf); + cd = iconv_open(CS_EUC_JP_MS, CS_UTF_8); if (cd == (iconv_t)-1) { cd = iconv_open(CS_EUC_JP, CS_UTF_8); @@ -487,30 +491,26 @@ static void conv_utf8toeuc(gchar *outbuf, gint outlen, const gchar *inbuf) g_warning("conv_utf8toeuc(): %s\n", g_strerror(errno)); iconv_ok = FALSE; - strncpy2(outbuf, inbuf, outlen); - return; + return g_strdup(inbuf); } } } - tmpstr = conv_iconv_strdup_with_cd(inbuf, cd, NULL); - if (tmpstr) { - strncpy2(outbuf, tmpstr, outlen); - g_free(tmpstr); - } else - strncpy2(outbuf, inbuf, outlen); + return conv_iconv_strdup_with_cd(inbuf, cd, NULL); } -static void conv_utf8tojis(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_utf8tojis(const gchar *inbuf) { - gchar *eucstr; + gchar *eucstr, *jisstr; - Xalloca(eucstr, outlen, return); + eucstr = conv_utf8toeuc(inbuf); + jisstr = conv_euctojis(eucstr); + g_free(eucstr); - conv_utf8toeuc(eucstr, outlen, inbuf); - conv_euctojis(outbuf, outlen, eucstr); + return jisstr; } +#if 0 static gchar valid_eucjp_tbl[][96] = { /* 0xa2a0 - 0xa2ff */ { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, @@ -635,6 +635,7 @@ static void conv_unreadable_eucjp(gchar *str) *p++ = SUBST_CHAR; } } +#endif static void conv_unreadable_8bit(gchar *str) { @@ -649,6 +650,7 @@ static void conv_unreadable_8bit(gchar *str) } } +#if 0 static void conv_unreadable_latin(gchar *str) { register guchar *p = str; @@ -662,6 +664,7 @@ static void conv_unreadable_latin(gchar *str) p++; } } +#endif #define NCV '\0' @@ -771,58 +774,65 @@ CharSet conv_guess_ja_encoding(const gchar *str) return guessed; } -static void conv_jistodisp(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_jistodisp(const gchar *inbuf) { - conv_jistoutf8(outbuf, outlen, inbuf); + return conv_jistoutf8(inbuf); } -static void conv_sjistodisp(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_sjistodisp(const gchar *inbuf) { - conv_sjistoutf8(outbuf, outlen, inbuf); + return conv_sjistoutf8(inbuf); } -static void conv_euctodisp(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_euctodisp(const gchar *inbuf) { - conv_euctoutf8(outbuf, outlen, inbuf); + return conv_euctoutf8(inbuf); } -void conv_utf8todisp(gchar *outbuf, gint outlen, const gchar *inbuf) +gchar *conv_utf8todisp(const gchar *inbuf) { if (g_utf8_validate(inbuf, -1, NULL) == TRUE) - strncpy2(outbuf, inbuf, outlen); + return g_strdup(inbuf); else - conv_ustodisp(outbuf, outlen, inbuf); + return conv_ustodisp(inbuf); } -static void conv_anytodisp(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_anytodisp(const gchar *inbuf) { - conv_anytoutf8(outbuf, outlen, inbuf); + gchar *outbuf; + + outbuf = conv_anytoutf8(inbuf); if (g_utf8_validate(outbuf, -1, NULL) != TRUE) conv_unreadable_8bit(outbuf); + + return outbuf; } -static void conv_ustodisp(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_ustodisp(const gchar *inbuf) { - strncpy2(outbuf, inbuf, outlen); + gchar *outbuf; + + outbuf = g_strdup(inbuf); conv_unreadable_8bit(outbuf); + + return outbuf; } -void conv_localetodisp(gchar *outbuf, gint outlen, const gchar *inbuf) +gchar *conv_localetodisp(const gchar *inbuf) { - gchar *tmpstr; - - tmpstr = conv_iconv_strdup(inbuf, conv_get_locale_charset_str(), - CS_INTERNAL, NULL); - if (tmpstr) { - strncpy2(outbuf, tmpstr, outlen); - g_free(tmpstr); - } else - conv_utf8todisp(outbuf, outlen, inbuf); + gchar *str; + + str = conv_iconv_strdup(inbuf, conv_get_locale_charset_str(), + CS_INTERNAL, NULL); + if (!str) + str = conv_utf8todisp(inbuf); + + return str; } -static void conv_noconv(gchar *outbuf, gint outlen, const gchar *inbuf) +static gchar *conv_noconv(const gchar *inbuf) { - strncpy2(outbuf, inbuf, outlen); + return g_strdup(inbuf); } CodeConverter *conv_code_converter_new(const gchar *src_encoding, @@ -846,25 +856,13 @@ void conv_code_converter_destroy(CodeConverter *conv) g_free(conv); } -gint conv_convert(CodeConverter *conv, gchar *outbuf, gint outlen, - const gchar *inbuf) +gchar *conv_convert(CodeConverter *conv, const gchar *inbuf) { if (conv->code_conv_func != conv_noconv) - conv->code_conv_func(outbuf, outlen, inbuf); - else { - gchar *str; - - str = conv_iconv_strdup + return conv->code_conv_func(inbuf); + else + return conv_iconv_strdup (inbuf, conv->src_encoding, conv->dest_encoding, NULL); - if (!str) - return -1; - else { - strncpy2(outbuf, str, outlen); - g_free(str); - } - } - - return 0; } gchar *conv_codeset_strdup(const gchar *inbuf, @@ -877,22 +875,16 @@ gchar *conv_codeset_strdup_full(const gchar *inbuf, const gchar *src_code, const gchar *dest_code, gint *error) { - gchar *buf; - size_t len; CodeConvFunc conv_func; conv_func = conv_get_code_conv_func(src_code, dest_code); if (conv_func != conv_noconv) { - len = (strlen(inbuf) + 1) * 3; - buf = g_malloc(len); - if (!buf) { - if (error) - *error = -1; - return NULL; - } + gchar *outbuf; - conv_func(buf, len, inbuf); - return g_realloc(buf, strlen(buf) + 1); + outbuf = conv_func(inbuf); + if (!outbuf && error) + *error = -1; + return outbuf; } return conv_iconv_strdup(inbuf, src_code, dest_code, error); @@ -1558,31 +1550,31 @@ const gchar *conv_get_current_locale(void) gchar *conv_unmime_header(const gchar *str, const gchar *default_encoding) { - gchar buf[BUFFSIZE]; + gchar *buf; + gchar *decoded_str; if (is_ascii_str(str)) return unmime_header(str); if (default_encoding) { - gchar *utf8_buf; - - utf8_buf = conv_codeset_strdup + buf = conv_codeset_strdup (str, default_encoding, CS_INTERNAL); - if (utf8_buf) { - gchar *decoded_str; - - decoded_str = unmime_header(utf8_buf); - g_free(utf8_buf); + if (buf) { + decoded_str = unmime_header(buf); + g_free(buf); return decoded_str; } } if (conv_get_locale_charset() == C_EUC_JP) - conv_anytodisp(buf, sizeof(buf), str); + buf = conv_anytodisp(str); else - conv_localetodisp(buf, sizeof(buf), str); + buf = conv_localetodisp(str); + + decoded_str = unmime_header(buf); + g_free(buf); - return unmime_header(buf); + return decoded_str; } #define MAX_LINELEN 76 @@ -1782,7 +1774,7 @@ void conv_encode_header(gchar *dest, gint len, const gchar *src, gint conv_copy_file(const gchar *src, const gchar *dest, const gchar *encoding) { FILE *src_fp, *dest_fp; - gchar buf[BUFFSIZE], outbuf[BUFFSIZE]; + gchar buf[BUFFSIZE]; CodeConverter *conv; gboolean err = FALSE; @@ -1804,9 +1796,13 @@ gint conv_copy_file(const gchar *src, const gchar *dest, const gchar *encoding) conv = conv_code_converter_new(encoding, NULL); while (fgets(buf, sizeof(buf), src_fp) != NULL) { - if (conv_convert(conv, outbuf, sizeof(outbuf), buf) == 0) + gchar *outbuf; + + outbuf = conv_convert(conv, buf); + if (outbuf) { fputs(outbuf, dest_fp); - else + g_free(outbuf); + } else fputs(buf, dest_fp); } diff --git a/src/codeconv.h b/src/codeconv.h index 65955d0d..c322f61a 100644 --- a/src/codeconv.h +++ b/src/codeconv.h @@ -92,7 +92,7 @@ typedef enum C_TCVN5712_1 } CharSet; -typedef void (*CodeConvFunc) (gchar *outbuf, gint outlen, const gchar *inbuf); +typedef gchar *(*CodeConvFunc) (const gchar *inbuf); struct _CodeConverter { @@ -171,17 +171,15 @@ struct _CodeConverter //void conv_mb_alnum(gchar *str); -CharSet conv_guess_ja_encoding(const gchar *str); +CharSet conv_guess_ja_encoding (const gchar *str); -void conv_utf8todisp (gchar *outbuf, gint outlen, const gchar *inbuf); -void conv_localetodisp (gchar *outbuf, gint outlen, const gchar *inbuf); +gchar *conv_utf8todisp (const gchar *inbuf); +gchar *conv_localetodisp (const gchar *inbuf); CodeConverter *conv_code_converter_new (const gchar *src_encoding, const gchar *dest_encoding); void conv_code_converter_destroy (CodeConverter *conv); -gint conv_convert (CodeConverter *conv, - gchar *outbuf, - gint outlen, +gchar *conv_convert (CodeConverter *conv, const gchar *inbuf); gchar *conv_codeset_strdup (const gchar *inbuf, @@ -225,7 +225,7 @@ gchar *html_parse(HTMLParser *parser) static HTMLState html_read_line(HTMLParser *parser) { gchar buf[HTMLBUFSIZE]; - gchar buf2[HTMLBUFSIZE]; + gchar *conv_str; gint index; if (fgets(buf, sizeof(buf), parser->fp) == NULL) { @@ -233,11 +233,13 @@ static HTMLState html_read_line(HTMLParser *parser) return HTML_EOF; } - if (conv_convert(parser->conv, buf2, sizeof(buf2), buf) < 0) { + conv_str = conv_convert(parser->conv, buf); + if (!conv_str) { index = parser->bufp - parser->buf->str; - conv_utf8todisp(buf2, sizeof(buf2), buf); - g_string_append(parser->buf, buf2); + conv_str = conv_utf8todisp(buf); + g_string_append(parser->buf, conv_str); + g_free(conv_str); parser->bufp = parser->buf->str + index; @@ -246,7 +248,8 @@ static HTMLState html_read_line(HTMLParser *parser) index = parser->bufp - parser->buf->str; - g_string_append(parser->buf, buf2); + g_string_append(parser->buf, conv_str); + g_free(conv_str); parser->bufp = parser->buf->str + index; diff --git a/src/procheader.c b/src/procheader.c index f88396cb..a3698b2c 100644 --- a/src/procheader.c +++ b/src/procheader.c @@ -779,7 +779,7 @@ void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer) { struct tm *lt; gchar *default_format = "%y/%m/%d(%a) %H:%M"; - gchar *tmp; + gchar *tmp, *buf; Xalloca(tmp, len + 1, dest[0] = '\0'; return;); @@ -790,5 +790,7 @@ void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer) else strftime(tmp, len, default_format, lt); - conv_localetodisp(dest, len, tmp); + buf = conv_localetodisp(tmp); + strncpy2(dest, buf, len); + g_free(buf); } diff --git a/src/rfc2015.c b/src/rfc2015.c index 7496e38a..1a12d35c 100644 --- a/src/rfc2015.c +++ b/src/rfc2015.c @@ -157,7 +157,8 @@ sig_status_full (gpgme_ctx_t ctx, gpgme_verify_result_t result) gpgme_signature_t sig; time_t created; struct tm *ctime_val; - char ctime_str[80], ctime_str_utf8[80]; + gchar ctime_str[80]; + gchar *ctime_str_utf8; gchar *retval; str = g_string_new (""); @@ -169,11 +170,11 @@ sig_status_full (gpgme_ctx_t ctx, gpgme_verify_result_t result) ctime_val = localtime (&created); strftime (ctime_str, sizeof (ctime_str), "%c", ctime_val); - conv_localetodisp (ctime_str_utf8, - sizeof (ctime_str_utf8), ctime_str); + ctime_str_utf8 = conv_localetodisp (ctime_str); g_string_sprintfa (str, _("Signature made at %s\n"), ctime_str_utf8); + g_free (ctime_str_utf8); } sig_status_for_key(str, ctx, sig); if (sig->next) diff --git a/src/sourcewindow.c b/src/sourcewindow.c index 986184ab..1b80687e 100644 --- a/src/sourcewindow.c +++ b/src/sourcewindow.c @@ -153,12 +153,10 @@ void source_window_append(SourceWindow *sourcewin, const gchar *str) buffer = gtk_text_view_get_buffer(text); - len = strlen(str) + 1; - Xalloca(out, len, return); - conv_utf8todisp(out, len, str); - + out = conv_utf8todisp(str); gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1); gtk_text_buffer_insert(buffer, &iter, out, -1); + g_free(out); } static void source_window_size_alloc_cb(GtkWidget *widget, 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) diff --git a/src/unmime.c b/src/unmime.c index 1365c3ce..fedf44f4 100644 --- a/src/unmime.c +++ b/src/unmime.c @@ -116,10 +116,8 @@ gchar *unmime_header(const gchar *encoded_str) /* convert to UTF-8 */ conv_str = conv_codeset_strdup(decoded_text, charset, NULL); - if (!conv_str) { - conv_str = g_malloc(len + 1); - conv_utf8todisp(conv_str, len + 1, decoded_text); - } + if (!conv_str) + conv_str = conv_utf8todisp(decoded_text); g_string_append(outbuf, conv_str); g_free(conv_str); |