diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-10-17 05:39:27 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-10-17 05:39:27 +0800 |
commit | 19ebd1a8475274e074a3fad27dcf326a162bc1ff (patch) | |
tree | c85934717a7b37f13ff2ee69135736de91ff96c3 /widgets/misc | |
parent | 8ed14acbc89554342447d38b21456550e05731e6 (diff) | |
download | gsoc2013-evolution-19ebd1a8475274e074a3fad27dcf326a162bc1ff.tar.gz gsoc2013-evolution-19ebd1a8475274e074a3fad27dcf326a162bc1ff.tar.zst gsoc2013-evolution-19ebd1a8475274e074a3fad27dcf326a162bc1ff.zip |
Don't include the byte reserved for the nul in the outleft size.
2002-10-16 Jeffrey Stedfast <fejj@ximian.com>
* gal/widgets/e-unicode.c (e_utf8_from_gtk_string_sized): Don't
include the byte reserved for the nul in the outleft size.
(e_utf8_from_iconv_string_sized): Same.
(e_utf8_to_iconv_string_sized): Here too, but also make sure we
pad the end of the resulting string with enough nul bytes (4) so
that even multi-byte charsets are terminated correctly.
(e_utf8_to_gtk_string_sized): Again here.
svn path=/trunk/; revision=18377
Diffstat (limited to 'widgets/misc')
-rw-r--r-- | widgets/misc/e-unicode.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/widgets/misc/e-unicode.c b/widgets/misc/e-unicode.c index a291597a7d..6a1363d705 100644 --- a/widgets/misc/e-unicode.c +++ b/widgets/misc/e-unicode.c @@ -257,7 +257,7 @@ e_utf8_from_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes) ib = string; ibl = bytes; new = ob = g_new (gchar, ibl * 6 + 1); - obl = ibl * 6 + 1; + obl = ibl * 6; while (ibl > 0) { e_iconv (ic, &ib, &ibl, &ob, &obl); @@ -319,9 +319,9 @@ e_utf8_to_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes) ib = string; ibl = bytes; - new = ob = g_new (gchar, ibl * 4 + 1); - obl = ibl * 4 + 1; - + new = ob = g_new (char, ibl * 4 + 4); + obl = ibl * 4; + while (ibl > 0) { e_iconv (ic, &ib, &ibl, &ob, &obl); if (ibl > 0) { @@ -337,13 +337,16 @@ e_utf8_to_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes) ib += len; ibl = bytes - (ib - string); if (ibl > bytes) ibl = 0; + + /* FIXME: this is wrong... what if the destination charset is 16 or 32 bit? */ *ob++ = '_'; obl--; } } - - *ob = '\0'; - + + /* Make sure to terminate with plenty of padding */ + memset (ob, 0, 4); + return new; } @@ -446,7 +449,7 @@ e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes ib = string; ibl = bytes; new = ob = g_new (gchar, ibl * 6 + 1); - obl = ibl * 6 + 1; + obl = ibl * 6; while (ibl > 0) { e_iconv (ic, &ib, &ibl, &ob, &obl); @@ -505,8 +508,8 @@ e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) /* If iconv is missing we assume either iso-10646 or iso-8859-1 */ xfs = GDK_FONT_XFONT (widget->style->font); twobyte = (widget->style->font->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0))); - - new = g_new (unsigned char, bytes * 4 + 1); + + new = g_new (unsigned char, bytes * 4 + 2); u = string; len = 0; @@ -517,14 +520,18 @@ e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) } new[len++] = uc & 0xff; } - new[len] = '\0'; + + new[len++] = '\0'; + if (twobyte) + new[len] = '\0'; + return new; } ib = string; ibl = bytes; - new = ob = g_new (gchar, ibl * 4 + 1); - obl = ibl * 4 + 1; + new = ob = g_new (gchar, ibl * 4 + 4); + obl = ibl * 4; while (ibl > 0) { e_iconv (ic, &ib, &ibl, &ob, &obl); @@ -545,11 +552,12 @@ e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes) obl--; } } - - *ob = '\0'; - + + /* Make sure to terminate with plenty of padding */ + memset (ob, 0, 4); + e_iconv_close(ic); - + return new; } |