From: Pierre Habouzit Date: Fri, 27 Oct 2006 23:39:39 +0000 (+0200) Subject: the “I found my first real bug” commit. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=59926571aaec3e38cec09d0d9fa34f4a4b887309 the “I found my first real bug” commit. yes, compiler warning flags are useful you know ? also remove the very bad ICONV_CONST idea. if your compiler is stupid enough not to know about const, then compile with -Dconst and stop the bullshit. --- diff --git a/browser.c b/browser.c index 1a1f71e..d111765 100644 --- a/browser.c +++ b/browser.c @@ -49,7 +49,7 @@ static struct mapping_t FolderHelp[] = { {N_("Chdir"), OP_CHANGE_DIRECTORY}, {N_("Mask"), OP_ENTER_MASK}, {N_("Help"), OP_HELP}, - {NULL} + {NULL, OP_NULL} }; #ifdef USE_NNTP @@ -61,7 +61,7 @@ static struct mapping_t FolderNewsHelp[] = { {N_("Catchup"), OP_CATCHUP}, {N_("Mask"), OP_ENTER_MASK}, {N_("Help"), OP_HELP}, - {NULL} + {NULL, OP_NULL} }; #endif @@ -167,8 +167,8 @@ static const char *folder_format_str (char *dest, size_t destlen, char op, const char *elsestring, unsigned long data, format_flag flags) { - char fn[SHORT_STRING], tmp[SHORT_STRING], permission[11]; - char date[16], *t_fmt; + char fn[SHORT_STRING], tmp[SHORT_STRING], permission[11], date[16]; + const char *t_fmt; time_t tnow; FOLDER *folder = (FOLDER *) data; struct passwd *pw; @@ -197,7 +197,7 @@ static const char *folder_format_str (char *dest, size_t destlen, char op, case 'f': { - char *s; + const char *s; #ifdef USE_IMAP if (folder->ff->imap) diff --git a/charset.c b/charset.c index 683afc9..63bc81c 100644 --- a/charset.c +++ b/charset.c @@ -124,7 +124,7 @@ static struct { "latin6", "iso-8859-10"}, /* this is not a bug */ { "l6", "iso-8859-10"}, { - "csISOLatin6" "iso-8859-10"}, { + "csISOLatin6", "iso-8859-10"}, { "csKOI8r", "koi8-r"}, { "MS_Kanji", "Shift_JIS"}, /* Note the underscore! */ { @@ -260,7 +260,7 @@ iconv_t iconv_open (const char *tocode, const char *fromcode) return (iconv_t) (-1); } -size_t iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, +size_t iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft) { return 0; @@ -315,12 +315,12 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) * if you're supplying an outrepl, the target charset should be. */ -size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, +size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft, - ICONV_CONST char **inrepls, const char *outrepl) + const char **inrepls, const char *outrepl) { size_t ret = 0, ret1; - ICONV_CONST char *ib = *inbuf; + const char *ib = *inbuf; size_t ibl = *inbytesleft; char *ob = *outbuf; size_t obl = *outbytesleft; @@ -332,10 +332,10 @@ size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, if (ibl && obl && errno == EILSEQ) { if (inrepls) { /* Try replacing the input */ - ICONV_CONST char **t; + const char **t; for (t = inrepls; *t; t++) { - ICONV_CONST char *ib1 = *t; + const char *ib1 = *t; size_t ibl1 = str_len (*t); char *ob1 = ob; size_t obl1 = obl; @@ -386,7 +386,7 @@ int mutt_convert_string (char **ps, const char *from, const char *to, int flags) { iconv_t cd; - ICONV_CONST char *repls[] = { "\357\277\275", "?", 0 }; + const char *repls[] = { "\357\277\275", "?", 0 }; char *s = *ps; if (!s || !*s) @@ -394,11 +394,11 @@ int mutt_convert_string (char **ps, const char *from, const char *to, if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t) - 1) { int len; - ICONV_CONST char *ib; + const char *ib; char *buf, *ob; size_t ibl, obl; - ICONV_CONST char **inrepls = 0; - char *outrepl = 0; + const char **inrepls = NULL; + const char *outrepl = NULL; if (mutt_is_utf8 (to)) outrepl = "\357\277\275"; @@ -442,7 +442,7 @@ struct fgetconv_s { char *ob; char *ib; size_t ibl; - ICONV_CONST char **inrepls; + const char **inrepls; }; struct fgetconv_not { @@ -455,7 +455,7 @@ FGETCONV *fgetconv_open (FILE * file, const char *from, const char *to, { struct fgetconv_s *fc; iconv_t cd = (iconv_t) - 1; - static ICONV_CONST char *repls[] = { "\357\277\275", "?", 0 }; + static const char *repls[] = { "\357\277\275", "?", 0 }; if (from && to) cd = mutt_iconv_open (to, from, flags); @@ -512,7 +512,7 @@ int fgetconv (FGETCONV * _fc) if (fc->ibl) { size_t obl = sizeof (fc->bufo); - iconv (fc->cd, (ICONV_CONST char **) &fc->ib, &fc->ibl, &fc->ob, &obl); + iconv (fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl); if (fc->p < fc->ob) return (unsigned char) *(fc->p)++; } @@ -536,7 +536,7 @@ int fgetconv (FGETCONV * _fc) if (fc->ibl) { size_t obl = sizeof (fc->bufo); - mutt_iconv (fc->cd, (ICONV_CONST char **) &fc->ib, &fc->ibl, &fc->ob, + mutt_iconv (fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl, fc->inrepls, 0); if (fc->p < fc->ob) return (unsigned char) *(fc->p)++; @@ -556,7 +556,7 @@ void fgetconv_close (FGETCONV ** _fc) mem_free (_fc); } -char *mutt_get_first_charset (const char *charset) +const char *mutt_get_first_charset (const char *charset) { static char fcharset[SHORT_STRING]; const char *c, *c1; @@ -570,7 +570,7 @@ char *mutt_get_first_charset (const char *charset) return fcharset; } -static size_t convert_string (ICONV_CONST char *f, size_t flen, +static size_t convert_string (const char *f, size_t flen, const char *from, const char *to, char **t, size_t * tlen) { diff --git a/charset.h b/charset.h index 482339b..bba1605 100644 --- a/charset.h +++ b/charset.h @@ -19,19 +19,18 @@ typedef void *iconv_t; #endif #ifndef HAVE_ICONV -#define ICONV_CONST const iconv_t iconv_open (const char *, const char *); -size_t iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *); +size_t iconv (iconv_t, const char **, size_t *, char **, size_t *); int iconv_close (iconv_t); #endif int mutt_convert_string (char **, const char *, const char *, int); -char *mutt_get_first_charset (const char *); +const char *mutt_get_first_charset (const char *); int mutt_convert_nonmime_string (char **); iconv_t mutt_iconv_open (const char *, const char *, int); -size_t mutt_iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *, - ICONV_CONST char **, const char *); +size_t mutt_iconv (iconv_t, const char **, size_t *, char **, size_t *, + const char **, const char *); typedef void *FGETCONV; diff --git a/complete.c b/complete.c index c909486..f451e1a 100644 --- a/complete.c +++ b/complete.c @@ -103,12 +103,8 @@ int mutt_complete (char *s, size_t slen) #ifdef USE_IMAP /* we can use '/' as a delimiter, imap_complete rewrites it */ if (*s == '=' || *s == '+' || *s == '!') { - if (*s == '!') - p = NONULL (Spoolfile); - else - p = NONULL (Maildir); - - mutt_concat_path (imap_path, p, s + 1, sizeof (imap_path)); + const char *q = NONULL(*s == '!' ? Spoolfile : Maildir); + mutt_concat_path (imap_path, q, s + 1, sizeof (imap_path)); } else strfcpy (imap_path, s, sizeof (imap_path)); diff --git a/gnupgparse.c b/gnupgparse.c index c29ab84..e4f0a57 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -84,7 +84,7 @@ static void fix_uid (char *uid) if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != (iconv_t) - 1) { int n = s - uid + 1; /* chars available in original buffer */ char *buf; - ICONV_CONST char *ib; + const char *ib; char *ob; size_t ibl, obl; diff --git a/intl/dcigettext.c b/intl/dcigettext.c index c7f4506..7e9653c 100644 --- a/intl/dcigettext.c +++ b/intl/dcigettext.c @@ -930,7 +930,7 @@ _nl_find_msg (struct loaded_l10nfile *domain_file, outleft = freemem_size - sizeof (size_t); if (iconv (domain->conv, - (ICONV_CONST char **) &inptr, &inleft, + (const char **) &inptr, &inleft, &outptr, &outleft) != (size_t) (-1)) { diff --git a/mbyte.c b/mbyte.c index 1ff911c..6993422 100644 --- a/mbyte.c +++ b/mbyte.c @@ -91,7 +91,7 @@ void mutt_set_charset (char *charset) static size_t wcrtomb_iconv (char *s, wchar_t wc, iconv_t cd) { char buf[MB_LEN_MAX]; - ICONV_CONST char *ib; + const char *ib; char *ob; size_t ibl, obl, r; @@ -138,7 +138,7 @@ size_t mbrtowc_iconv (wchar_t * pwc, const char *s, size_t n, mbstate_t * ps, iconv_t cd) { static mbstate_t mbstate; - ICONV_CONST char *ib, *ibmax; + const char *ib, *ibmax; char *ob, *t; size_t ibl, obl, k, r; char bufi[8], bufo[6]; diff --git a/rfc2047.c b/rfc2047.c index 2d57d6a..d4e7d6a 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -46,10 +46,10 @@ extern char RFC822Specials[]; -typedef size_t (*encoder_t) (char *, ICONV_CONST char *, size_t, +typedef size_t (*encoder_t) (char *, const char *, size_t, const char *); -static size_t convert_string (ICONV_CONST char *f, size_t flen, +static size_t convert_string (const char *f, size_t flen, const char *from, const char *to, char **t, size_t * tlen) { @@ -143,7 +143,7 @@ char *mutt_choose_charset (const char *fromcode, const char *charsets, return tocode; } -static size_t b_encoder (char *s, ICONV_CONST char *d, size_t dlen, +static size_t b_encoder (char *s, const char *d, size_t dlen, const char *tocode) { char *s0 = s; @@ -180,7 +180,7 @@ static size_t b_encoder (char *s, ICONV_CONST char *d, size_t dlen, return s - s0; } -static size_t q_encoder (char *s, ICONV_CONST char *d, size_t dlen, +static size_t q_encoder (char *s, const char *d, size_t dlen, const char *tocode) { char hex[] = "0123456789ABCDEF"; @@ -215,13 +215,13 @@ static size_t q_encoder (char *s, ICONV_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 (ICONV_CONST char *d, size_t dlen, +static size_t try_block (const char *d, size_t dlen, const char *fromcode, const char *tocode, encoder_t * encoder, size_t * wlen) { char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; iconv_t cd; - ICONV_CONST char *ib; + const char *ib; char *ob, *p; size_t ibl, obl; int count, len, len_b, len_q; @@ -288,7 +288,7 @@ static size_t encode_block (char *s, char *d, size_t dlen, { char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; iconv_t cd; - ICONV_CONST char *ib; + const char *ib; char *ob; size_t ibl, obl, n1, n2; @@ -344,7 +344,7 @@ 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 (ICONV_CONST char *d, size_t dlen, int col, +static int rfc2047_encode (const char *d, size_t dlen, int col, const char *fromcode, const char *charsets, char **e, size_t * elen, char *specials) { diff --git a/sendlib.c b/sendlib.c index e47825c..4571e7a 100644 --- a/sendlib.c +++ b/sendlib.c @@ -604,7 +604,7 @@ static size_t convert_file_to (FILE * file, const char *fromcode, #ifdef HAVE_ICONV iconv_t cd1, *cd; char bufi[256], bufu[512], bufo[4 * sizeof (bufi)]; - ICONV_CONST char *ib, *ub; + const char *ib, *ub; char *ob; size_t ibl, obl, ubl, ubl1, n, ret; int i; diff --git a/state.c b/state.c index 7b44389..3e10619 100644 --- a/state.c +++ b/state.c @@ -31,7 +31,7 @@ static void state_prefix_put (const char *d, size_t dlen, STATE * s) void mutt_convert_to_state (iconv_t cd, char *bufi, size_t * l, STATE * s) { char bufo[BUFO_SIZE]; - ICONV_CONST char *ib; + const char *ib; char *ob; size_t ibl, obl;