From: Pierre Habouzit Date: Fri, 3 Nov 2006 23:23:25 +0000 (+0100) Subject: fix signedness issues. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=b4e1f0143e321a296e7b90c5b01051b94a8b20cc;ds=sidebyside fix signedness issues. now the rewrite will begin Signed-off-by: Pierre Habouzit --- diff --git a/charset.h b/charset.h index 5b3b732..1b5f025 100644 --- a/charset.h +++ b/charset.h @@ -29,10 +29,10 @@ typedef void *iconv_t; # define my_iconv(a,b,c,d,e) 0 # define iconv_close(a) 0 #else -static inline ssize_t my_iconv(iconv_t ict, const char **inbuf, size_t *ilen, - char **outbuf, size_t *olen) +static inline ssize_t my_iconv(iconv_t ict, const char **inbuf, ssize_t *ilen, + char **outbuf, ssize_t *olen) { - return iconv(ict, (char **)inbuf, ilen, outbuf, olen); + return iconv(ict, (char **)inbuf, (size_t*)ilen, outbuf, (size_t*)olen); } #endif diff --git a/lib-mime/mime.h b/lib-mime/mime.h index 464a840..4f2d62c 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -158,7 +158,7 @@ extern const char RFC822Specials[]; /****************************************************************************/ 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); void rfc2047_encode_string(char **); void rfc2047_encode_adrlist(address_t *, const char *); diff --git a/lib-mime/rfc2047.c b/lib-mime/rfc2047.c index 442d2e4..1d4fa46 100644 --- a/lib-mime/rfc2047.c +++ b/lib-mime/rfc2047.c @@ -69,13 +69,12 @@ typedef size_t (*encoder_t) (char *, const char *, size_t, returns number of converted chars from f, see iconv(3) */ static ssize_t -convert_string(const char *from, const char *f, size_t flen, - const char *to, char **t, size_t *tlen) +convert_string(const char *from, const char *f, ssize_t flen, + const char *to, char **t, ssize_t *tlen) { iconv_t cd; char *buf, *ob; - size_t obl; - ssize_t n; + ssize_t obl, n; int e; cd = mutt_iconv_open(to, from, 0); @@ -106,16 +105,16 @@ convert_string(const char *from, const char *f, size_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, ':'); @@ -130,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) { @@ -236,15 +235,15 @@ 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) { @@ -262,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; } @@ -304,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); @@ -320,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); } @@ -334,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"); @@ -366,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; @@ -539,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)