X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mime%2Frfc2047.c;h=1d4fa46ed803c01fa83c5b9d57b36e5777ea8de6;hp=6e79beec9e0c8fe0ea05b562c15d7d162627e53f;hb=b4e1f0143e321a296e7b90c5b01051b94a8b20cc;hpb=83532821ae9fab034d0d630b78330c9ea4ff4cf3 diff --git a/lib-mime/rfc2047.c b/lib-mime/rfc2047.c index 6e79bee..1d4fa46 100644 --- a/lib-mime/rfc2047.c +++ b/lib-mime/rfc2047.c @@ -70,11 +70,11 @@ typedef size_t (*encoder_t) (char *, const char *, size_t, */ static ssize_t convert_string(const char *from, const char *f, ssize_t flen, - const char *to, char **t, size_t *tlen) + const char *to, char **t, ssize_t *tlen) { iconv_t cd; char *buf, *ob; - size_t obl, n; + ssize_t obl, n; int e; cd = mutt_iconv_open(to, from, 0); @@ -105,16 +105,16 @@ convert_string(const char *from, const char *f, ssize_t flen, } char *mutt_choose_charset(const char *fromcode, const char *charsets, - char *u, size_t ulen, char **d, size_t *dlen) + char *u, ssize_t ulen, char **d, ssize_t *dlen) { char canonical_buff[LONG_STRING]; char *e = 0, *tocode = 0; - size_t elen = 0, bestn = 0; + ssize_t elen = 0, bestn = 0; const char *p, *q; for (p = charsets; p; p = q ? q + 1 : 0) { char *s, *t; - size_t slen, n; + ssize_t slen, n; q = strchr (p, ':'); @@ -129,7 +129,7 @@ char *mutt_choose_charset(const char *fromcode, const char *charsets, t = p_dupstr(p, n); n = convert_string(fromcode, u, ulen, t, &s, &slen); - if (n == (size_t) (-1)) + if (n < 0) continue; if (!tocode || n < bestn) { @@ -235,23 +235,24 @@ static size_t q_encoder (char *s, const char *d, size_t dlen, * tocode, unless fromcode is 0, in which case the data is assumed to * be already in tocode, which should be 8-bit and stateless. */ -static size_t try_block (const char *d, size_t dlen, +static size_t try_block (const char *d, ssize_t dlen, const char *fromcode, const char *tocode, - encoder_t * encoder, size_t * wlen) + encoder_t * encoder, ssize_t *wlen) { char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; iconv_t cd; const char *ib; char *ob, *p; - size_t ibl, obl; + ssize_t ibl, obl; int count, len, len_b, len_q; if (fromcode) { cd = mutt_iconv_open (tocode, fromcode, 0); assert (cd != (iconv_t) (-1)); ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - m_strlen(tocode); - if (my_iconv(cd, &ib, &ibl, &ob, &obl) == (size_t) (-1) || - my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) { + if (my_iconv(cd, &ib, &ibl, &ob, &obl) < 0 + || my_iconv(cd, 0, 0, &ob, &obl) < 0) + { assert (errno == E2BIG); iconv_close (cd); assert (ib > d); @@ -260,8 +261,8 @@ static size_t try_block (const char *d, size_t dlen, iconv_close (cd); } else { - if (dlen > sizeof (buf1) - m_strlen(tocode)) - return sizeof (buf1) - m_strlen(tocode) + 1; + if (dlen > ssizeof(buf1) - m_strlen(tocode)) + return ssizeof(buf1) - m_strlen(tocode) + 1; memcpy (buf1, d, dlen); ob = buf1 + dlen; } @@ -302,15 +303,15 @@ static size_t try_block (const char *d, size_t dlen, * Encode the data (d, dlen) into s using the encoder. * Return the length of the encoded word. */ -static size_t encode_block (char *s, char *d, size_t dlen, +static size_t encode_block (char *s, char *d, ssize_t dlen, const char *fromcode, const char *tocode, encoder_t encoder) { char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; + ssize_t ibl, obl, n1, n2; iconv_t cd; const char *ib; char *ob; - size_t ibl, obl, n1, n2; if (fromcode) { cd = mutt_iconv_open (tocode, fromcode, 0); @@ -318,7 +319,7 @@ static size_t encode_block (char *s, char *d, size_t dlen, ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - m_strlen(tocode); n1 = my_iconv(cd, &ib, &ibl, &ob, &obl); n2 = my_iconv(cd, 0, 0, &ob, &obl); - assert (n1 != (size_t) (-1) && n2 != (size_t) (-1)); + assert (n1 >= 0 && n2 >= 0); iconv_close (cd); return (*encoder) (s, buf1, ob - buf1, tocode); } @@ -332,9 +333,9 @@ static size_t encode_block (char *s, char *d, size_t dlen, * and set the length *wlen of the encoded word and *encoder. * We start in column col, which limits the length of the word. */ -static size_t choose_block (char *d, size_t dlen, int col, - const char *fromcode, const char *tocode, - encoder_t * encoder, size_t * wlen) +static size_t choose_block(char *d, size_t dlen, int col, + const char *fromcode, const char *tocode, + encoder_t *encoder, ssize_t *wlen) { size_t n, nn; int utf8 = fromcode && !ascii_strcasecmp (fromcode, "UTF-8"); @@ -364,16 +365,16 @@ static size_t choose_block (char *d, size_t dlen, int col, * The input data is assumed to be a single line starting at column col; * if col is non-zero, the preceding character was a space. */ -static int rfc2047_encode (const char *d, size_t dlen, int col, +static int rfc2047_encode (const char *d, ssize_t dlen, int col, const char *fromcode, const char *charsets, - char **e, size_t * elen, char *specials) + char **e, ssize_t *elen, const char *specials) { int ret = 0; char *buf; - size_t bufpos, buflen; + ssize_t bufpos, buflen; char *u, *t0, *t1, *t; char *s0, *s1; - size_t ulen, r, n, wlen; + ssize_t ulen, r, n, wlen; encoder_t encoder; char *tocode1 = 0; const char *tocode; @@ -537,7 +538,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, void _rfc2047_encode_string (char **pd, int encode_specials, int col) { char *e; - size_t elen; + ssize_t elen; const char *charsets; if (!Charset || !*pd) @@ -556,7 +557,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col) } void rfc2047_encode_string(char **pd) { - _rfc2047_encode_string(a, 0, 32); + _rfc2047_encode_string(pd, 0, 32); } void rfc2047_encode_adrlist (address_t * addr, const char *tag)