X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=rfc2047.c;h=ae4a52b9623811fdb2e21c6352a003ecca7c4949;hp=a81a84963b3b9cc5e4ddf86af4f67534c78d348d;hb=b3cb6ed8d36c550a2e589910ce51bbc8352ff57c;hpb=5e53f9e5f65aa5b3af6f5af9d868403536534afb diff --git a/rfc2047.c b/rfc2047.c index a81a849..ae4a52b 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -12,6 +12,8 @@ # include "config.h" #endif +#include + #include "mutt.h" #include "ascii.h" #include "mime.h" @@ -62,11 +64,11 @@ static size_t convert_string (const char *f, size_t flen, if (cd == (iconv_t) (-1)) return (size_t) (-1); obl = 4 * flen + 1; - ob = buf = mem_malloc (obl); + ob = buf = p_new(char, obl); n = my_iconv(cd, &f, &flen, &ob, &obl); if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) { e = errno; - mem_free (&buf); + p_delete(&buf); iconv_close (cd); errno = e; return (size_t) (-1); @@ -104,9 +106,7 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets, n > (ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 2 - 12)) continue; - t = mem_malloc (n + 1); - memcpy (t, p, n); - t[n] = '\0'; + t = p_dupstr(p, n); n = convert_string (u, ulen, fromcode, t, &s, &slen); if (n == (size_t) (-1)) @@ -114,21 +114,21 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets, if (!tocode || n < bestn) { bestn = n; - mem_free (&tocode); + p_delete(&tocode); tocode = t; if (d) { - mem_free (&e); + p_delete(&e); e = s; } else - mem_free (&s); + p_delete(&s); elen = slen; if (!bestn) break; } else { - mem_free (&t); - mem_free (&s); + p_delete(&t); + p_delete(&s); } } if (tocode) { @@ -357,15 +357,13 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, encoder_t encoder; char *tocode1 = 0; const char *tocode; - char *icode = "UTF-8"; + const char *icode = "UTF-8"; /* Try to convert to UTF-8. */ if (convert_string (d, dlen, fromcode, icode, &u, &ulen)) { ret = 1; icode = 0; - u = mem_malloc ((ulen = dlen) + 1); - memcpy (u, d, dlen); - u[ulen] = 0; + u = p_dupstr(d, ulen = dlen); } /* Find earliest and latest things we must encode. */ @@ -448,7 +446,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, /* Initialise the output buffer with the us-ascii prefix. */ buflen = 2 * ulen; - buf = mem_malloc (buflen); + buf = p_new(char, buflen); bufpos = t0 - u; memcpy (buf, u, t0 - u); @@ -506,8 +504,8 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, bufpos += wlen; memcpy (buf + bufpos, t1, u + ulen - t1); - mem_free (&tocode1); - mem_free (&u); + p_delete(&tocode1); + p_delete(&u); buf[buflen] = '\0'; @@ -520,7 +518,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col) { char *e; size_t elen; - char *charsets; + const char *charsets; if (!Charset || !*pd) return; @@ -533,7 +531,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col) Charset, charsets, &e, &elen, encode_specials ? RFC822Specials : NULL); - mem_free (pd); + p_delete(pd); *pd = e; } @@ -557,7 +555,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len) int enc = 0, count = 0; char *charset = NULL; - pd = d0 = mem_malloc (str_len (s)); + pd = d0 = p_new(char, str_len(s)); for (pp = s; (pp1 = strchr (pp, '?')); pp = pp1 + 1) { count++; @@ -567,9 +565,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len) t = pp1; if ((t1 = memchr (pp, '*', t - pp))) t = t1; - charset = mem_malloc (t - pp + 1); - memcpy (charset, pp, t - pp); - charset[t - pp] = '\0'; + charset = p_dupstr(pp, t - pp); break; case 3: if (toupper ((unsigned char) *pp) == 'Q') @@ -577,8 +573,8 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len) else if (toupper ((unsigned char) *pp) == 'B') enc = ENCBASE64; else { - mem_free (&charset); - mem_free (&d0); + p_delete(&charset); + p_delete(&d0); return (-1); } break; @@ -625,8 +621,8 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len) if (charset) mutt_convert_string (&d0, charset, Charset, M_ICONV_HOOK_FROM); strfcpy (d, d0, len); - mem_free (&charset); - mem_free (&d0); + p_delete(&charset); + p_delete(&d0); return (0); } @@ -714,7 +710,7 @@ void rfc2047_decode (char **pd) return; dlen = 4 * str_len (s); /* should be enough */ - d = d0 = mem_malloc (dlen + 1); + d = d0 = p_new(char, dlen + 1); while (*s && dlen > 0) { if (!(p = find_encoded_word (s, &q))) { @@ -730,8 +726,7 @@ void rfc2047_decode (char **pd) char *t; size_t tlen; - t = mem_malloc (n + 1); - strfcpy (t, s, n + 1); + t = p_dupstr(s, n); if (mutt_convert_nonmime_string (&t) == 0) { tlen = str_len (t); strncpy (d, t, tlen); @@ -741,7 +736,7 @@ void rfc2047_decode (char **pd) strncpy (d, s, n); d += n; } - mem_free (&t); + p_delete(&t); break; } } @@ -789,7 +784,7 @@ void rfc2047_decode (char **pd) } *d = 0; - mem_free (pd); + p_delete(pd); *pd = d0; str_adjust (pd); }