From b157354a50ffac1dd999928c2a92db60de208684 Mon Sep 17 00:00:00 2001 From: Federico Kircheis Date: Wed, 10 Jul 2019 20:30:30 +0200 Subject: [PATCH] Improve const-correctness of * convert_file_to * get_quote_level * mutt_write_one_header * classify_quote * gen_string_hash * gen_case_string_hash * mutt_buffer_enter_fname_full * parse_references --- curs_lib.c | 2 +- email/parse.c | 2 +- hdrline.c | 3 +-- mutt/hash.c | 4 ++-- pager.c | 6 +++--- rfc3676.c | 2 +- sendlib.c | 9 ++++----- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index 64b9ff957..486fed55a 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -652,7 +652,7 @@ int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname, struct KeyEvent ch; SET_COLOR(MT_COLOR_PROMPT); - mutt_window_mvaddstr(MuttMessageWindow, 0, 0, (char *) prompt); + mutt_window_mvaddstr(MuttMessageWindow, 0, 0, prompt); addstr(_(" ('?' for list): ")); NORMAL_COLOR; if (mutt_buffer_len(fname)) diff --git a/email/parse.c b/email/parse.c index 4745da6f7..0214e2b73 100644 --- a/email/parse.c +++ b/email/parse.c @@ -250,7 +250,7 @@ static void parse_content_disposition(const char *s, struct Body *ct) * @param head List to receive the references * @param s String to parse */ -static void parse_references(struct ListHead *head, char *s) +static void parse_references(struct ListHead *head, const char *s) { char *m = NULL; const char *sp = NULL; diff --git a/hdrline.c b/hdrline.c index 96e85f8fc..6b16b5b2b 100644 --- a/hdrline.c +++ b/hdrline.c @@ -683,12 +683,11 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co if (optional && ((op == '[') || (op == '('))) { - char *is = NULL; now = time(NULL); struct tm tm = mutt_date_localtime(now); now -= (op == '(') ? e->received : e->date_sent; - is = (char *) prec; + char *is = (char *) prec; bool invert = false; if (*is == '>') { diff --git a/mutt/hash.c b/mutt/hash.c index cc628beb2..28607146b 100644 --- a/mutt/hash.c +++ b/mutt/hash.c @@ -45,7 +45,7 @@ static size_t gen_string_hash(union HashKey key, size_t n) { size_t h = 0; - unsigned char *s = (unsigned char *) key.strkey; + const unsigned char *s = (const unsigned char *) key.strkey; while (*s) h += ((h << 7) + *s++); @@ -76,7 +76,7 @@ static int cmp_string_key(union HashKey a, union HashKey b) static size_t gen_case_string_hash(union HashKey key, size_t n) { size_t h = 0; - unsigned char *s = (unsigned char *) key.strkey; + const unsigned char *s = (const unsigned char *) key.strkey; while (*s) h += ((h << 7) + tolower(*s++)); diff --git a/pager.c b/pager.c index b059300f5..9288d79c4 100644 --- a/pager.c +++ b/pager.c @@ -524,7 +524,7 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt { struct QClass *q_list = *quote_list; struct QClass *qc = NULL, *tmp = NULL, *ptr = NULL, *save = NULL; - char *tail_qptr = NULL; + const char *tail_qptr = NULL; int offset, tail_lng; int index = -1; @@ -650,7 +650,7 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt q_list = q_list->down; tail_lng = length - offset; - tail_qptr = (char *) qptr + offset; + tail_qptr = qptr + offset; while (q_list) { @@ -752,7 +752,7 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt q_list = q_list->down; tail_lng = length - offset; - tail_qptr = (char *) qptr + offset; + tail_qptr = qptr + offset; continue; } diff --git a/rfc3676.c b/rfc3676.c index 46cc13bce..41000e96b 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -67,7 +67,7 @@ struct FlowedState static int get_quote_level(const char *line) { int quoted = 0; - char *p = (char *) line; + const char *p = line; while (p && (*p == '>')) { diff --git a/sendlib.c b/sendlib.c index 887639e73..74c305017 100644 --- a/sendlib.c +++ b/sendlib.c @@ -768,7 +768,7 @@ static void update_content_info(struct Content *info, struct ContentState *s, * in. */ static size_t convert_file_to(FILE *fp, const char *fromcode, int ncodes, - const char **tocodes, int *tocode, struct Content *info) + char const *const *tocodes, int *tocode, struct Content *info) { char bufi[256], bufu[512], bufo[4 * sizeof(bufi)]; size_t ret; @@ -960,7 +960,7 @@ static size_t convert_file_from_to(FILE *fp, const char *fromcodes, const char * continue; fcode = mutt_str_substr_dup(c, c1); - ret = convert_file_to(fp, fcode, ncodes, (const char **) tcode, &cn, info); + ret = convert_file_to(fp, fcode, ncodes, (char const *const *) tcode, &cn, info); if (ret != (size_t)(-1)) { *fromcode = fcode; @@ -974,7 +974,7 @@ static size_t convert_file_from_to(FILE *fp, const char *fromcodes, const char * else { /* There is only one fromcode */ - ret = convert_file_to(fp, fromcodes, ncodes, (const char **) tcode, &cn, info); + ret = convert_file_to(fp, fromcodes, ncodes, (char const *const *) tcode, &cn, info); if (ret != (size_t)(-1)) { *tocode = tcode[cn]; @@ -2123,7 +2123,6 @@ static int write_one_header(FILE *fp, int pfxw, int max, int wraplen, const char int mutt_write_one_header(FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, CopyHeaderFlags chflags) { - char *p = (char *) value; char *last = NULL, *line = NULL; int max = 0, w, rc = -1; int pfxw = mutt_strwidth(pfx); @@ -2162,7 +2161,7 @@ int mutt_write_one_header(FILE *fp, const char *tag, const char *value, } } - p = v; + char *p = v; last = v; line = v; while (p && *p) -- 2.40.0