diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 2000-05-20 15:46:39 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 2000-05-20 15:46:39 +0000 |
commit | 92f926fc34d3cd2dfb5fae7ccb12905e4bc412ad (patch) | |
tree | 2774e06752a810b3ffd4d833ce09ab162c692dee /charset.c | |
parent | 9f395d0586ec5315e9b6e88035aef6a28e276a90 (diff) |
String conversion patch from EGE.
Diffstat (limited to 'charset.c')
-rw-r--r-- | charset.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -378,23 +378,24 @@ bail: /* - * Convert a string in place + * Convert a string * Used in rfc2047.c and rfc2231.c */ -int mutt_convert_string (char *s, size_t len, const char *from, const char *to) +int mutt_convert_string (char **ps, const char *from, const char *to) { iconv_t cd; const char *repls[] = { "\357\277\275", "?", 0 }; + char *s = *ps; if (!s || !*s) return 0; if (to && from && (cd = mutt_iconv_open (to, from)) != (iconv_t)-1) { - int n; + int len; const char *ib; - char *c, *ob; + char *buf, *ob; size_t ibl, obl; const char **inrepls = 0; char *outrepl = 0; @@ -406,14 +407,16 @@ int mutt_convert_string (char *s, size_t len, const char *from, const char *to) else outrepl = "?"; - n = strlen (s); - c = safe_malloc (n); - memcpy (c, s, n); - ib = c, ibl = n, ob = s, obl = len ? len-1 : n; + len = strlen (s); + ib = s, ibl = len + 1; + obl = MB_LEN_MAX * ibl; + ob = buf = safe_malloc (obl + 1); mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); - free (c); iconv_close (cd); + free (s); *ob = '\0'; + *ps = safe_strdup (buf); + free (buf); return 0; } else |