From da2ecbcbe6c87b6d94f8e86f164b03373d778a5f Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 4 Oct 2017 13:14:08 +0100 Subject: [PATCH] reduce scope of variables C99 allows a 'for' loop to define its variable. This reduces the variable's scope making its use clearer. --- browser.c | 13 ++++------- charset.c | 3 +-- color.c | 3 +-- commands.c | 17 +++++++------- compose.c | 10 ++++---- copy.c | 5 ++-- curs_main.c | 54 ++++++++++++++++++-------------------------- editmsg.c | 4 +--- flags.c | 6 ++--- handler.c | 6 ++--- headers.c | 3 +-- help.c | 5 ++-- history.c | 8 +++---- imap/command.c | 19 ++++++++-------- imap/imap.c | 44 ++++++++++++++++++------------------ imap/message.c | 21 +++++++++-------- imap/utf7.c | 4 ++-- init.c | 33 ++++++++++----------------- keymap.c | 12 +++++----- lib/file.c | 3 +-- lib/sha1.c | 5 ++-- lib/string.c | 7 ++---- menu.c | 4 +--- mutt_notmuch.c | 16 ++++++------- mutt_ssl.c | 17 ++++++-------- mutt_ssl_gnutls.c | 15 ++++++------ muttlib.c | 14 ++++-------- mx.c | 4 ++-- ncrypt/crypt.c | 11 ++++----- ncrypt/crypt_gpgme.c | 26 +++++++++------------ newsrc.c | 17 +++++++------- pager.c | 6 ++--- parameter.c | 4 +--- pattern.c | 11 ++++----- pgpewrap.c | 3 +-- pgppubring.c | 18 +++++++-------- pop_lib.c | 4 +--- recvattach.c | 43 +++++++++++++++-------------------- remailer.c | 21 ++++++++--------- rfc2047.c | 16 ++++++------- score.c | 4 +--- send.c | 13 ++++------- sendlib.c | 23 ++++++++++--------- sidebar.c | 15 +++++------- sort.c | 7 +++--- thread.c | 6 ++--- txt2c.c | 3 +-- 47 files changed, 257 insertions(+), 349 deletions(-) diff --git a/browser.c b/browser.c index f70c8ef82d6..e1caf83cc08 100644 --- a/browser.c +++ b/browser.c @@ -1096,11 +1096,10 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf else { struct NntpServer *nserv = CurrentNewsSrv; - unsigned int j; /* default state for news reader mode is browse subscribed newsgroups */ buffy = 0; - for (j = 0; j < nserv->groups_num; j++) + for (unsigned int j = 0; j < nserv->groups_num; j++) { struct NntpData *nntp_data = nserv->groups_list[j]; if (nntp_data && nntp_data->subscribed) @@ -1468,13 +1467,12 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf if (multiple) { char **tfiles = NULL; - int j, k; if (menu->tagged) { *numfiles = menu->tagged; tfiles = safe_calloc(*numfiles, sizeof(char *)); - for (j = 0, k = 0; j < state.entrylen; j++) + for (int j = 0, k = 0; j < state.entrylen; j++) { struct FolderFile ff = state.entry[j]; char full[_POSIX_PATH_MAX]; @@ -1947,12 +1945,11 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf if (option(OPT_NEWS)) { struct NntpServer *nserv = CurrentNewsSrv; - unsigned int j; if (nntp_newsrc_parse(nserv) < 0) break; - for (j = 0; j < nserv->groups_num; j++) + for (unsigned int j = 0; j < nserv->groups_num; j++) { struct NntpData *nntp_data = nserv->groups_list[j]; if (nntp_data) @@ -2046,9 +2043,7 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf } if (i == OP_SUBSCRIBE_PATTERN) { - unsigned int k; - - for (k = 0; nserv && k < nserv->groups_num; k++) + for (unsigned int k = 0; nserv && (k < nserv->groups_num); k++) { struct NntpData *nntp_data = nserv->groups_list[k]; if (nntp_data && nntp_data->group && !nntp_data->subscribed) diff --git a/charset.c b/charset.c index c1d239ebb7f..8208eaca3c5 100644 --- a/charset.c +++ b/charset.c @@ -629,14 +629,13 @@ void fgetconv_close(FGETCONV **_fc) bool mutt_check_charset(const char *s, bool strict) { - int i; iconv_t cd; if (mutt_is_utf8(s)) return true; if (!strict) - for (i = 0; PreferredMIMENames[i].key; i++) + for (int i = 0; PreferredMIMENames[i].key; i++) { if ((mutt_strcasecmp(PreferredMIMENames[i].key, s) == 0) || (mutt_strcasecmp(PreferredMIMENames[i].pref, s) == 0)) diff --git a/color.c b/color.c index 7785a13ca9a..50191027483 100644 --- a/color.c +++ b/color.c @@ -207,7 +207,6 @@ void ci_start_color(void) static char *get_color_name(char *dest, size_t destlen, int val) { static const char *const missing[3] = { "brown", "lightgray", "default" }; - int i; switch (val) { @@ -224,7 +223,7 @@ static char *get_color_name(char *dest, size_t destlen, int val) return dest; } - for (i = 0; Colors[i].name; i++) + for (int i = 0; Colors[i].name; i++) { if (Colors[i].value == val) { diff --git a/commands.c b/commands.c index b6196043834..98ff9b81080 100644 --- a/commands.c +++ b/commands.c @@ -392,7 +392,7 @@ static void pipe_msg(struct Header *h, FILE *fp, int decode, int print) static int _mutt_pipe_message(struct Header *h, char *cmd, int decode, int print, int split, char *sep) { - int i, rc = 0; + int rc = 0; pid_t thepid; FILE *fpout = NULL; @@ -425,7 +425,7 @@ static int _mutt_pipe_message(struct Header *h, char *cmd, int decode, if (WithCrypto && decode) { - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) if (Context->hdrs[Context->v2r[i]]->tagged) { mutt_message_hook(Context, Context->hdrs[Context->v2r[i]], MUTT_MESSAGEHOOK); @@ -438,7 +438,7 @@ static int _mutt_pipe_message(struct Header *h, char *cmd, int decode, if (split) { - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (Context->hdrs[Context->v2r[i]]->tagged) { @@ -470,7 +470,7 @@ static int _mutt_pipe_message(struct Header *h, char *cmd, int decode, return 1; } set_option(OPT_KEEP_QUIET); - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (Context->hdrs[Context->v2r[i]]->tagged) { @@ -746,7 +746,7 @@ int _mutt_save_message(struct Header *h, struct Context *ctx, int delete, int de */ int mutt_save_message(struct Header *h, int delete, int decode, int decrypt) { - int i, need_buffy_cleanup; + int need_buffy_cleanup; int need_passphrase = 0, app = 0; char prompt[SHORT_STRING], buf[_POSIX_PATH_MAX]; struct Context ctx; @@ -775,7 +775,7 @@ int mutt_save_message(struct Header *h, int delete, int decode, int decrypt) { /* look for the first tagged message */ - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (Context->hdrs[Context->v2r[i]]->tagged) { @@ -885,7 +885,7 @@ int mutt_save_message(struct Header *h, int delete, int decode, int decrypt) if (Context->magic == MUTT_NOTMUCH) nm_longrun_init(Context, true); #endif - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (Context->hdrs[Context->v2r[i]]->tagged) { @@ -1067,13 +1067,12 @@ static int _mutt_check_traditional_pgp(struct Header *h, int *redraw) int mutt_check_traditional_pgp(struct Header *h, int *redraw) { - int i; int rv = 0; if (h && !(h->security & PGP_TRADITIONAL_CHECKED)) rv = _mutt_check_traditional_pgp(h, redraw); else { - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) if (Context->hdrs[Context->v2r[i]]->tagged && !(Context->hdrs[Context->v2r[i]]->security & PGP_TRADITIONAL_CHECKED)) { diff --git a/compose.c b/compose.c index 0e211c7472a..b9baaf195df 100644 --- a/compose.c +++ b/compose.c @@ -205,13 +205,12 @@ static void calc_header_width_padding(int idx, const char *header, int calc_max) static void init_header_padding(void) { static short done = 0; - int i; if (done) return; done = 1; - for (i = 0; i <= HDR_XCOMMENTTO; i++) + for (int i = 0; i <= HDR_XCOMMENTTO; i++) calc_header_width_padding(i, _(Prompts[i]), 1); /* Don't include "Sign as: " in the MaxHeaderWidth calculation. It @@ -219,7 +218,7 @@ static void init_header_padding(void) * the other fields look funny. */ calc_header_width_padding(HDR_CRYPTINFO, _(Prompts[HDR_CRYPTINFO]), 0); - for (i = 0; i <= HDR_XCOMMENTTO; i++) + for (int i = 0; i <= HDR_XCOMMENTTO; i++) { HeaderPadding[i] += MaxHeaderWidth; if (HeaderPadding[i] < 0) @@ -648,14 +647,13 @@ static void compose_menu_redraw(struct Menu *menu) */ static unsigned long cum_attachs_size(struct Menu *menu) { - size_t s; - unsigned short i; + size_t s = 0; struct AttachCtx *actx = menu->data; struct AttachPtr **idx = actx->idx; struct Content *info = NULL; struct Body *b = NULL; - for (i = 0, s = 0; i < actx->idxlen; i++) + for (unsigned short i = 0; i < actx->idxlen; i++) { b = idx[i]->content; diff --git a/copy.c b/copy.c index 6242a85ee78..ee0f5d28371 100644 --- a/copy.c +++ b/copy.c @@ -496,13 +496,12 @@ int mutt_copy_header(FILE *in, struct Header *h, FILE *out, int flags, const cha static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t datelen) { int dellines = 0; - long l; int ch; if (b->deleted) { fseeko(fp, b->offset, SEEK_SET); - for (l = b->length; l; l--) + for (long l = b->length; l; l--) { ch = getc(fp); if (ch == EOF) @@ -513,7 +512,7 @@ static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t d dellines -= 3; *length -= b->length - (84 + datelen); /* Count the number of digits exceeding the first one to write the size */ - for (l = 10; b->length >= l; l *= 10) + for (long l = 10; b->length >= l; l *= 10) (*length)++; } else diff --git a/curs_main.c b/curs_main.c index 5b5d12c2a42..6938a09a686 100644 --- a/curs_main.c +++ b/curs_main.c @@ -205,8 +205,7 @@ static void collapse_all(struct Menu *menu, int toggle) /* Restore the cursor */ mutt_set_virtual(Context); - int j; - for (j = 0; j < Context->vcount; j++) + for (int j = 0; j < Context->vcount; j++) { if (Context->hdrs[Context->v2r[j]]->index == base->index) { @@ -220,9 +219,7 @@ static void collapse_all(struct Menu *menu, int toggle) static int ci_next_undeleted(int msgno) { - int i; - - for (i = msgno + 1; i < Context->vcount; i++) + for (int i = msgno + 1; i < Context->vcount; i++) if (!Context->hdrs[Context->v2r[i]]->deleted) return i; return -1; @@ -230,9 +227,7 @@ static int ci_next_undeleted(int msgno) static int ci_previous_undeleted(int msgno) { - int i; - - for (i = msgno - 1; i >= 0; i--) + for (int i = msgno - 1; i >= 0; i--) if (!Context->hdrs[Context->v2r[i]]->deleted) return i; return -1; @@ -246,11 +241,11 @@ static int ci_previous_undeleted(int msgno) */ static int ci_first_message(void) { - int old = -1, i; + int old = -1; if (Context && Context->msgcount) { - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (!Context->hdrs[Context->v2r[i]]->read && !Context->hdrs[Context->v2r[i]]->deleted) @@ -309,14 +304,13 @@ static int mx_toggle_write(struct Context *ctx) static void resort_index(struct Menu *menu) { - int i; struct Header *current = CURHDR; menu->current = -1; mutt_sort_headers(Context, 0); /* Restore the current message */ - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (Context->hdrs[Context->v2r[i]] == current) { @@ -338,7 +332,6 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun { /* store pointers to the newly added messages */ struct Header **save_new = NULL; - int j; if (!menu || !ctx) return; @@ -357,20 +350,20 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun * they will be visible in the limited view */ if (ctx->pattern) { - for (j = (check == MUTT_REOPENED) ? 0 : oldcount; j < ctx->msgcount; j++) + for (int i = (check == MUTT_REOPENED) ? 0 : oldcount; i < ctx->msgcount; i++) { - if (!j) + if (!i) ctx->vcount = 0; if (mutt_pattern_exec(ctx->limit_pattern, MUTT_MATCH_FULL_ADDRESS, ctx, - ctx->hdrs[j], NULL)) + ctx->hdrs[i], NULL)) { assert(ctx->vcount < ctx->msgcount); - ctx->hdrs[j]->virtual = ctx->vcount; - ctx->v2r[ctx->vcount] = j; - ctx->hdrs[j]->limited = true; + ctx->hdrs[i]->virtual = ctx->vcount; + ctx->v2r[ctx->vcount] = i; + ctx->hdrs[i]->limited = true; ctx->vcount++; - struct Body *b = ctx->hdrs[j]->content; + struct Body *b = ctx->hdrs[i]->content; ctx->vsize += b->length + b->offset - b->hdr_offset; } } @@ -381,8 +374,8 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun ((Sort & SORT_MASK) == SORT_THREADS)) { save_new = safe_malloc(sizeof(struct Header *) * (ctx->msgcount - oldcount)); - for (j = oldcount; j < ctx->msgcount; j++) - save_new[j - oldcount] = ctx->hdrs[j]; + for (int i = oldcount; i < ctx->msgcount; i++) + save_new[i - oldcount] = ctx->hdrs[i]; } /* if the mailbox was reopened, need to rethread from scratch */ @@ -407,14 +400,12 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun } else if (oldcount) { - for (j = 0; j < ctx->msgcount - oldcount; j++) + for (int i = 0; i < ctx->msgcount - oldcount; i++) { - int k; - - for (k = 0; k < ctx->msgcount; k++) + for (int k = 0; k < ctx->msgcount; k++) { struct Header *h = ctx->hdrs[k]; - if (h == save_new[j] && (!ctx->pattern || h->limited)) + if (h == save_new[i] && (!ctx->pattern || h->limited)) mutt_uncollapse_thread(ctx, h); } } @@ -427,11 +418,11 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun if (oldcount) { /* restore the current message to the message it was pointing to */ - for (j = 0; j < ctx->vcount; j++) + for (int i = 0; i < ctx->vcount; i++) { - if (ctx->hdrs[ctx->v2r[j]]->index == menu->oldcurrent) + if (ctx->hdrs[ctx->v2r[i]]->index == menu->oldcurrent) { - menu->current = j; + menu->current = i; break; } } @@ -1348,7 +1339,6 @@ int mutt_index_menu(void) { struct Header *oldcur = CURHDR; struct Header *hdr = NULL; - int k; bool quiet = Context->quiet; if (rc2 < 0) @@ -1374,7 +1364,7 @@ int mutt_index_menu(void) /* try to restore old position */ else { - for (k = 0; k < Context->msgcount; k++) + for (int k = 0; k < Context->msgcount; k++) { if (Context->hdrs[k]->index == oldindex) { diff --git a/editmsg.c b/editmsg.c index daa435d9116..ebeb3e556bd 100644 --- a/editmsg.c +++ b/editmsg.c @@ -219,14 +219,12 @@ static int edit_one_message(struct Context *ctx, struct Header *cur) int mutt_edit_message(struct Context *ctx, struct Header *hdr) { - int j; - if (hdr) return edit_one_message(ctx, hdr); for (int i = 0; i < ctx->vcount; i++) { - j = ctx->v2r[i]; + int j = ctx->v2r[i]; if (ctx->hdrs[j]->tagged) { if (edit_one_message(ctx, ctx->hdrs[j]) == -1) diff --git a/flags.c b/flags.c index 20ad291ece3..d3b8ab50e27 100644 --- a/flags.c +++ b/flags.c @@ -334,9 +334,9 @@ void _mutt_set_flag(struct Context *ctx, struct Header *h, int flag, int bf, int */ void mutt_tag_set_flag(int flag, int bf) { - for (int j = 0; j < Context->vcount; j++) - if (Context->hdrs[Context->v2r[j]]->tagged) - mutt_set_flag(Context, Context->hdrs[Context->v2r[j]], flag, bf); + for (int i = 0; i < Context->vcount; i++) + if (Context->hdrs[Context->v2r[i]]->tagged) + mutt_set_flag(Context, Context->hdrs[Context->v2r[i]], flag, bf); } int mutt_thread_set_flag(struct Header *hdr, int flag, int bf, int subthread) diff --git a/handler.c b/handler.c index a4bbc712606..6ee1349d946 100644 --- a/handler.c +++ b/handler.c @@ -1289,8 +1289,6 @@ int mutt_can_decode(struct Body *a) return 1; else if (a->type == TYPEMULTIPART) { - struct Body *p = NULL; - if (WithCrypto) { if ((mutt_strcasecmp(a->subtype, "signed") == 0) || @@ -1298,9 +1296,9 @@ int mutt_can_decode(struct Body *a) return 1; } - for (p = a->parts; p; p = p->next) + for (struct Body *b = a->parts; b; b = b->next) { - if (mutt_can_decode(p)) + if (mutt_can_decode(b)) return 1; } } diff --git a/headers.c b/headers.c index 9c8b620ef39..f9de5acdc78 100644 --- a/headers.c +++ b/headers.c @@ -280,7 +280,6 @@ static int label_message(struct Context *ctx, struct Header *hdr, char *new) int mutt_label_message(struct Header *hdr) { char buf[LONG_STRING], *new = NULL; - int i; int changed; if (!Context || !Context->label_hash) @@ -312,7 +311,7 @@ int mutt_label_message(struct Header *hdr) else { #define HDR_OF(index) Context->hdrs[Context->v2r[(index)]] - for (i = 0; i < Context->vcount; ++i) + for (int i = 0; i < Context->vcount; ++i) { if (HDR_OF(i)->tagged) if (label_message(Context, HDR_OF(i), new)) diff --git a/help.c b/help.c index 0ba4e9a5b2a..941ac373ccd 100644 --- a/help.c +++ b/help.c @@ -47,20 +47,19 @@ static const char *HelpStrings[] = { static const struct Binding *help_lookup_function(int op, int menu) { - int i; const struct Binding *map = NULL; if (menu != MENU_PAGER) { /* first look in the generic map for the function */ - for (i = 0; OpGeneric[i].name; i++) + for (int i = 0; OpGeneric[i].name; i++) if (OpGeneric[i].op == op) return (&OpGeneric[i]); } if ((map = km_get_table(menu))) { - for (i = 0; map[i].name; i++) + for (int i = 0; map[i].name; i++) if (map[i].op == op) return (&map[i]); } diff --git a/history.c b/history.c index 5e09e003d78..199450f4591 100644 --- a/history.c +++ b/history.c @@ -96,13 +96,11 @@ static struct History *get_history(enum HistoryClass hclass) static void init_history(struct History *h) { - int i; - if (OldSize) { if (h->hist) { - for (i = 0; i <= OldSize; i++) + for (int i = 0; i <= OldSize; i++) FREE(&h->hist[i]); FREE(&h->hist); } @@ -292,7 +290,7 @@ static void save_history(enum HistoryClass hclass, const char *s) { static int n = 0; FILE *f = NULL; - char *tmp = NULL, *p = NULL; + char *tmp = NULL; if (!s || !*s) /* This shouldn't happen, but it's safer. */ return; @@ -309,7 +307,7 @@ static void save_history(enum HistoryClass hclass, const char *s) /* Format of a history item (1 line): ":|". We add a '|' in order to avoid lines ending with '\'. */ fprintf(f, "%d:", (int) hclass); - for (p = tmp; *p; p++) + for (char *p = tmp; *p; p++) { /* Don't copy \n as a history item must fit on one line. The string shouldn't contain such a character anyway, but as this can happen diff --git a/imap/command.c b/imap/command.c index f0d967654b1..2ac821223e7 100644 --- a/imap/command.c +++ b/imap/command.c @@ -334,7 +334,6 @@ static void cmd_parse_fetch(struct ImapData *idata, char *s) */ static void cmd_parse_capability(struct ImapData *idata, char *s) { - int x; bool found; char *bracket = NULL; @@ -351,23 +350,25 @@ static void cmd_parse_capability(struct ImapData *idata, char *s) while (*s) { found = false; - for (x = 0; x < CAPMAX; x++) - if (imap_wordcasecmp(Capabilities[x], s) == 0) + for (int i = 0; i < CAPMAX; i++) + { + if (imap_wordcasecmp(Capabilities[i], s) == 0) { - mutt_bit_set(idata->capabilities, x); - mutt_debug(4, " Found capability \"%s\": %d\n", Capabilities[x], x); + mutt_bit_set(idata->capabilities, i); + mutt_debug(4, " Found capability \"%s\": %d\n", Capabilities[i], i); found = true; break; } + } if (!found) { - for (x = 0; CapabilityAliases[x].name != NULL; x++) + for (int i = 0; CapabilityAliases[i].name != NULL; i++) { - if (imap_wordcasecmp(CapabilityAliases[x].name, s) == 0) + if (imap_wordcasecmp(CapabilityAliases[i].name, s) == 0) { - mutt_bit_set(idata->capabilities, CapabilityAliases[x].value); + mutt_bit_set(idata->capabilities, CapabilityAliases[i].value); mutt_debug(4, " Found capability \"%s\": %d\n", - CapabilityAliases[x].name, CapabilityAliases[x].value); + CapabilityAliases[i].name, CapabilityAliases[i].value); break; } } diff --git a/imap/imap.c b/imap/imap.c index 77f8b40a8ad..c5d6eb163d4 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1446,7 +1446,6 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) struct Header *h = NULL; struct Header **hdrs = NULL; int oldsort; - int n; int rc; idata = ctx->data; @@ -1479,9 +1478,9 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) { /* mark these messages as unchanged so second pass ignores them. Done * here so BOGUS UW-IMAP 4.7 SILENT FLAGS updates are ignored. */ - for (n = 0; n < ctx->msgcount; n++) - if (ctx->hdrs[n]->deleted && ctx->hdrs[n]->changed) - ctx->hdrs[n]->active = false; + for (int i = 0; i < ctx->msgcount; i++) + if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->changed) + ctx->hdrs[i]->active = false; mutt_message(_("Marking %d messages deleted..."), rc); } } @@ -1491,9 +1490,9 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) #endif /* save messages with real (non-flag) changes */ - for (n = 0; n < ctx->msgcount; n++) + for (int i = 0; i < ctx->msgcount; i++) { - h = ctx->hdrs[n]; + h = ctx->hdrs[i]; if (h->deleted) { @@ -1514,7 +1513,7 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) if ((h->env && (h->env->refs_changed || h->env->irt_changed)) || h->attach_del || h->xlabel_changed) { - mutt_message(_("Saving changed messages... [%d/%d]"), n + 1, ctx->msgcount); + mutt_message(_("Saving changed messages... [%d/%d]"), i + 1, ctx->msgcount); if (!appendctx) appendctx = mx_open_mailbox(ctx->path, MUTT_APPEND | MUTT_QUIET, NULL); if (!appendctx) @@ -1585,14 +1584,14 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) /* Update local record of server state to reflect the synchronization just * completed. imap_read_headers always overwrites hcache-origin flags, so * there is no need to mutate the hcache after flag-only changes. */ - for (n = 0; n < ctx->msgcount; n++) + for (int i = 0; i < ctx->msgcount; i++) { - HEADER_DATA(ctx->hdrs[n])->deleted = ctx->hdrs[n]->deleted; - HEADER_DATA(ctx->hdrs[n])->flagged = ctx->hdrs[n]->flagged; - HEADER_DATA(ctx->hdrs[n])->old = ctx->hdrs[n]->old; - HEADER_DATA(ctx->hdrs[n])->read = ctx->hdrs[n]->read; - HEADER_DATA(ctx->hdrs[n])->replied = ctx->hdrs[n]->replied; - ctx->hdrs[n]->changed = false; + HEADER_DATA(ctx->hdrs[i])->deleted = ctx->hdrs[i]->deleted; + HEADER_DATA(ctx->hdrs[i])->flagged = ctx->hdrs[i]->flagged; + HEADER_DATA(ctx->hdrs[i])->old = ctx->hdrs[i]->old; + HEADER_DATA(ctx->hdrs[i])->read = ctx->hdrs[i]->read; + HEADER_DATA(ctx->hdrs[i])->replied = ctx->hdrs[i]->replied; + ctx->hdrs[i]->changed = false; } ctx->changed = false; @@ -1638,7 +1637,6 @@ int imap_sync_mailbox(struct Context *ctx, int expunge) int imap_close_mailbox(struct Context *ctx) { struct ImapData *idata = NULL; - int i; idata = ctx->data; /* Check to see if the mailbox is actually open */ @@ -1674,7 +1672,7 @@ int imap_close_mailbox(struct Context *ctx) idata->msn_index_size = 0; idata->max_msn = 0; - for (i = 0; i < IMAP_CACHE_LEN; i++) + for (int i = 0; i < IMAP_CACHE_LEN; i++) { if (idata->cache[i].path) { @@ -1687,10 +1685,12 @@ int imap_close_mailbox(struct Context *ctx) } /* free IMAP part of headers */ - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) + { /* mailbox may not have fully loaded */ if (ctx->hdrs[i] && ctx->hdrs[i]->data) imap_free_header_data((struct ImapHeaderData **) &(ctx->hdrs[i]->data)); + } return 0; } @@ -2431,7 +2431,7 @@ int imap_fast_trash(struct Context *ctx, char *dest) char mbox[LONG_STRING]; char mmbox[LONG_STRING]; char prompt[LONG_STRING]; - int n, rc; + int rc; struct ImapMbox mx; bool triedcreate = false; struct Buffer *sync_cmd = NULL; @@ -2458,12 +2458,12 @@ int imap_fast_trash(struct Context *ctx, char *dest) imap_munge_mbox_name(idata, mmbox, sizeof(mmbox), mbox); sync_cmd = mutt_buffer_new(); - for (n = 0; n < ctx->msgcount; n++) + for (int i = 0; i < ctx->msgcount; i++) { - if (ctx->hdrs[n]->active && ctx->hdrs[n]->changed && - ctx->hdrs[n]->deleted && !ctx->hdrs[n]->purge) + if (ctx->hdrs[i]->active && ctx->hdrs[i]->changed && + ctx->hdrs[i]->deleted && !ctx->hdrs[i]->purge) { - rc = imap_sync_message_for_copy(idata, ctx->hdrs[n], sync_cmd, &err_continue); + rc = imap_sync_message_for_copy(idata, ctx->hdrs[i], sync_cmd, &err_continue); if (rc < 0) { mutt_debug(1, "imap_fast_trash: could not sync\n"); diff --git a/imap/message.c b/imap/message.c index 83e85821bae..a6c88cd3869 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1220,7 +1220,6 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int de char mmbox[LONG_STRING]; char prompt[LONG_STRING]; int rc; - int n; struct ImapMbox mx; int err_continue = MUTT_NO; int triedcreate = 0; @@ -1264,18 +1263,18 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int de /* if any messages have attachments to delete, fall through to FETCH * and APPEND. TODO: Copy what we can with COPY, fall through for the * remainder. */ - for (n = 0; n < ctx->msgcount; n++) + for (int i = 0; i < ctx->msgcount; i++) { - if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->attach_del) + if (ctx->hdrs[i]->tagged && ctx->hdrs[i]->attach_del) { mutt_debug(3, "imap_copy_messages: Message contains attachments to " "be deleted\n"); return 1; } - if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->active && ctx->hdrs[n]->changed) + if (ctx->hdrs[i]->tagged && ctx->hdrs[i]->active && ctx->hdrs[i]->changed) { - rc = imap_sync_message_for_copy(idata, ctx->hdrs[n], &sync_cmd, &err_continue); + rc = imap_sync_message_for_copy(idata, ctx->hdrs[i], &sync_cmd, &err_continue); if (rc < 0) { mutt_debug(1, "imap_copy_messages: could not sync\n"); @@ -1355,16 +1354,18 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int de if (delete) { if (!h) - for (n = 0; n < ctx->msgcount; n++) + { + for (int i = 0; i < ctx->msgcount; i++) { - if (ctx->hdrs[n]->tagged) + if (ctx->hdrs[i]->tagged) { - mutt_set_flag(ctx, ctx->hdrs[n], MUTT_DELETE, 1); - mutt_set_flag(ctx, ctx->hdrs[n], MUTT_PURGE, 1); + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1); + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1); if (option(OPT_DELETE_UNTAG)) - mutt_set_flag(ctx, ctx->hdrs[n], MUTT_TAG, 0); + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_TAG, 0); } } + } else { mutt_set_flag(ctx, h, MUTT_DELETE, 1); diff --git a/imap/utf7.c b/imap/utf7.c index b86ea16aa83..62da7725206 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -159,7 +159,7 @@ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len { char *buf = NULL, *p = NULL; int ch; - int n, i, b = 0, k = 0; + int n, b = 0, k = 0; bool base64 = false; /* @@ -211,7 +211,7 @@ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len u8len--; if (n > u8len) goto bail; - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) { if ((u8[i] & 0xc0) != 0x80) goto bail; diff --git a/init.c b/init.c index 82689989565..59eddb4da35 100644 --- a/init.c +++ b/init.c @@ -987,7 +987,6 @@ static int finish_source(struct Buffer *tmp, struct Buffer *s, static int parse_ifdef(struct Buffer *tmp, struct Buffer *s, unsigned long data, struct Buffer *err) { - int i, j; bool res = 0; struct Buffer token; @@ -1006,13 +1005,13 @@ static int parse_ifdef(struct Buffer *tmp, struct Buffer *s, unsigned long data, /* or a function? */ if (!res) { - for (i = 0; !res && (i < MENU_MAX); i++) + for (int i = 0; !res && (i < MENU_MAX); i++) { const struct Binding *b = km_get_table(Menus[i].value); if (!b) continue; - for (j = 0; b[j].name; j++) + for (int j = 0; b[j].name; j++) { if (mutt_strcmp(tmp->data, b[j].name) == 0) { @@ -1026,7 +1025,7 @@ static int parse_ifdef(struct Buffer *tmp, struct Buffer *s, unsigned long data, /* or a command? */ if (!res) { - for (i = 0; Commands[i].name; i++) + for (int i = 0; Commands[i].name; i++) { if (mutt_strcmp(tmp->data, Commands[i].name) == 0) { @@ -1144,10 +1143,9 @@ static int parse_unstailq(struct Buffer *buf, struct Buffer *s, static void _alternates_clean(void) { - int i; if (Context && Context->msgcount) { - for (i = 0; i < Context->msgcount; i++) + for (int i = 0; i < Context->msgcount; i++) Context->hdrs[i]->recip_valid = false; } } @@ -1262,10 +1260,9 @@ static int parse_unreplace_list(struct Buffer *buf, struct Buffer *s, static void clear_subject_mods(void) { - int i; if (Context && Context->msgcount) { - for (i = 0; i < Context->msgcount; i++) + for (int i = 0; i < Context->msgcount; i++) FREE(&Context->hdrs[i]->env->disp_subj); } } @@ -1526,10 +1523,9 @@ static int parse_group(struct Buffer *buf, struct Buffer *s, unsigned long data, */ static void _attachments_clean(void) { - int i; if (Context && Context->msgcount) { - for (i = 0; i < Context->msgcount; i++) + for (int i = 0; i < Context->msgcount; i++) Context->hdrs[i]->attach_valid = false; } } @@ -1949,9 +1945,8 @@ static int parse_alias(struct Buffer *buf, struct Buffer *s, unsigned long data, #ifdef DEBUG if (debuglevel >= 2) { - struct Address *a = NULL; /* A group is terminated with an empty address, so check a->mailbox */ - for (a = tmp->addr; a && a->mailbox; a = a->next) + for (struct Address *a = tmp->addr; a && a->mailbox; a = a->next) { if (!a->group) mutt_debug(3, "parse_alias: %s\n", a->mailbox); @@ -2259,14 +2254,14 @@ static void pretty_var(char *dst, size_t len, const char *option, const char *va static int check_charset(struct Option *opt, const char *val) { - char *p = NULL, *q = NULL, *s = safe_strdup(val); + char *q = NULL, *s = safe_strdup(val); int rc = 0; bool strict = (strcmp(opt->option, "send_charset") == 0); if (!s) return rc; - for (p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q)) + for (char *p = strtok_r(s, ":", &q); p; p = strtok_r(NULL, ":", &q)) { if (!*p) continue; @@ -2809,9 +2804,8 @@ static int parse_set(struct Buffer *tmp, struct Buffer *s, unsigned long data, (mutt_strcmp(MuttVars[idx].option, "reply_regexp") == 0)) { regmatch_t pmatch[1]; - int i; - for (i = 0; i < Context->msgcount; i++) + for (int i = 0; i < Context->msgcount; i++) { struct Envelope *e = Context->hdrs[i]->env; if (e && e->subject) @@ -3421,8 +3415,6 @@ static void candidate(char *dest, char *try, const char *src, int len) if (!dest || !try || !src) return; - int l; - if (strstr(src, try) == src) { matches_ensure_morespace(Num_matched); @@ -3431,6 +3423,7 @@ static void candidate(char *dest, char *try, const char *src, int len) strfcpy(dest, src, len); else { + int l; for (l = 0; src[l] && src[l] == dest[l]; l++) ; dest[l] = '\0'; @@ -4422,9 +4415,7 @@ void mutt_init(int skip_sys_rc, struct ListHead *commands) int mutt_get_hook_type(const char *name) { - const struct Command *c = NULL; - - for (c = Commands; c->name; c++) + for (const struct Command *c = Commands; c->name; c++) if (c->func == mutt_parse_hook && (mutt_strcasecmp(c->name, name) == 0)) return c->data; return 0; diff --git a/keymap.c b/keymap.c index 0f831cb1900..c43ec87215e 100644 --- a/keymap.c +++ b/keymap.c @@ -1088,7 +1088,7 @@ int mutt_parse_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, { const struct Binding *bindings = NULL; char *key = NULL; - int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], r = 0, nummenus, i; + int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], r = 0, nummenus; if ((key = parse_keymap(menu, s, sizeof(menu) / sizeof(menu[0]), &nummenus, err)) == NULL) return -1; @@ -1102,14 +1102,14 @@ int mutt_parse_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, } else if (mutt_strcasecmp("noop", buf->data) == 0) { - for (i = 0; i < nummenus; ++i) + for (int i = 0; i < nummenus; ++i) { km_bindkey(key, menu[i], OP_NULL); /* the `unbind' command */ } } else { - for (i = 0; i < nummenus; ++i) + for (int i = 0; i < nummenus; ++i) { /* The pager and editor menus don't use the generic map, * however for other menus try generic first. */ @@ -1143,7 +1143,7 @@ int mutt_parse_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, int mutt_parse_macro(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { - int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], r = -1, nummenus, i; + int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], r = -1, nummenus; char *seq = NULL; char *key = NULL; @@ -1169,7 +1169,7 @@ int mutt_parse_macro(struct Buffer *buf, struct Buffer *s, unsigned long data, } else { - for (i = 0; i < nummenus; ++i) + for (int i = 0; i < nummenus; ++i) { r = km_bind(key, menu[i], OP_MACRO, seq, buf->data); } @@ -1179,7 +1179,7 @@ int mutt_parse_macro(struct Buffer *buf, struct Buffer *s, unsigned long data, } else { - for (i = 0; i < nummenus; ++i) + for (int i = 0; i < nummenus; ++i) { r = km_bind(key, menu[i], OP_MACRO, buf->data, NULL); } diff --git a/lib/file.c b/lib/file.c index 971fddcef7f..0fbee2d988e 100644 --- a/lib/file.c +++ b/lib/file.c @@ -846,7 +846,6 @@ int mutt_mkdir(const char *path, mode_t mode) } errno = 0; - char *p = NULL; char _path[PATH_MAX]; const size_t len = strlen(path); @@ -863,7 +862,7 @@ int mutt_mkdir(const char *path, mode_t mode) /* Create a mutable copy */ strfcpy(_path, path, sizeof(_path)); - for (p = _path + 1; *p; p++) + for (char *p = _path + 1; *p; p++) { if (*p != '/') continue; diff --git a/lib/sha1.c b/lib/sha1.c index 56cfe66ec16..fe93572449b 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -232,11 +232,10 @@ void sha1_update(struct Sha1Ctx *context, const unsigned char *data, uint32_t le */ void sha1_final(unsigned char digest[20], struct Sha1Ctx *context) { - unsigned i; unsigned char finalcount[8]; unsigned char c; - for (i = 0; i < 8; i++) + for (unsigned int i = 0; i < 8; i++) { finalcount[i] = (unsigned char) ((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ @@ -250,7 +249,7 @@ void sha1_final(unsigned char digest[20], struct Sha1Ctx *context) sha1_update(context, &c, 1); } sha1_update(context, finalcount, 8); /* Should cause a sha1_transform() */ - for (i = 0; i < 20; i++) + for (unsigned int i = 0; i < 20; i++) { digest[i] = (unsigned char) ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); } diff --git a/lib/string.c b/lib/string.c index b1b8ef64308..4091b5614ef 100644 --- a/lib/string.c +++ b/lib/string.c @@ -514,9 +514,7 @@ char *mutt_skip_whitespace(char *p) */ void mutt_remove_trailing_ws(char *s) { - char *p = NULL; - - for (p = s + mutt_strlen(s) - 1; p >= s && ISSPACE(*p); p--) + for (char *p = s + mutt_strlen(s) - 1; p >= s && ISSPACE(*p); p--) *p = '\0'; } @@ -701,9 +699,8 @@ const char *rstrnstr(const char *haystack, size_t haystack_length, const char *n { int needle_length = strlen(needle); const char *haystack_end = haystack + haystack_length - needle_length; - const char *p = NULL; - for (p = haystack_end; p >= haystack; --p) + for (const char *p = haystack_end; p >= haystack; --p) { for (size_t i = 0; i < needle_length; ++i) { diff --git a/menu.c b/menu.c index bea90c04b80..b37b2ae3269 100644 --- a/menu.c +++ b/menu.c @@ -823,11 +823,9 @@ struct Menu *mutt_new_menu(int menu) void mutt_menu_destroy(struct Menu **p) { - int i; - if ((*p)->dialog) { - for (i = 0; i < (*p)->max; i++) + for (int i = 0; i < (*p)->max; i++) FREE(&(*p)->dialog[i]); FREE(&(*p)->dialog); diff --git a/mutt_notmuch.c b/mutt_notmuch.c index efcaca10400..ba889f60906 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -775,13 +775,13 @@ static int get_database_mtime(struct NmCtxData *data, time_t *mtime) static void apply_exclude_tags(notmuch_query_t *query) { - char *buf = NULL, *p = NULL, *end = NULL, *tag = NULL; + char *buf = NULL, *end = NULL, *tag = NULL; if (!NmExcludeTags || !*NmExcludeTags) return; buf = safe_strdup(NmExcludeTags); - for (p = buf; p && *p; p++) + for (char *p = buf; p && *p; p++) { if (!tag && isspace(*p)) continue; @@ -1382,13 +1382,13 @@ static int update_tags(notmuch_message_t *msg, const char *tags) */ static int update_header_flags(struct Context *ctx, struct Header *hdr, const char *tags) { - char *tag = NULL, *end = NULL, *p = NULL; + char *tag = NULL, *end = NULL; char *buf = safe_strdup(tags); if (!buf) return -1; - for (p = buf; p && *p; p++) + for (char *p = buf; p && *p; p++) { if (!tag && isspace(*p)) continue; @@ -2301,7 +2301,7 @@ static int nm_check_mailbox(struct Context *ctx, int *index_hint) time_t mtime = 0; notmuch_query_t *q = NULL; notmuch_messages_t *msgs = NULL; - int i, limit, new_flags = 0; + int limit, new_flags = 0; bool occult = false; if (!data || (get_database_mtime(data, &mtime) != 0)) @@ -2323,7 +2323,7 @@ static int nm_check_mailbox(struct Context *ctx, int *index_hint) data->oldmsgcount = ctx->msgcount; data->noprogress = true; - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) ctx->hdrs[i]->active = false; limit = get_limit(data); @@ -2338,7 +2338,7 @@ static int nm_check_mailbox(struct Context *ctx, int *index_hint) msgs = notmuch_query_search_messages(q); #endif - for (i = 0; notmuch_messages_valid(msgs) && ((limit == 0) || (i < limit)); + for (int i = 0; notmuch_messages_valid(msgs) && ((limit == 0) || (i < limit)); notmuch_messages_move_to_next(msgs), i++) { char old[_POSIX_PATH_MAX]; @@ -2385,7 +2385,7 @@ static int nm_check_mailbox(struct Context *ctx, int *index_hint) notmuch_message_destroy(m); } - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) { if (!ctx->hdrs[i]->active) { diff --git a/mutt_ssl.c b/mutt_ssl.c index 24764671cfe..13de32e27ac 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -358,7 +358,6 @@ static void x509_fingerprint(char *s, int l, X509 *cert, const EVP_MD *(*hashfun { unsigned char md[EVP_MAX_MD_SIZE]; unsigned int n; - int j; if (!X509_digest(cert, hashfunc(), md, &n)) { @@ -366,10 +365,10 @@ static void x509_fingerprint(char *s, int l, X509 *cert, const EVP_MD *(*hashfun } else { - for (j = 0; j < (int) n; j++) + for (int i = 0; i < (int) n; i++) { char ch[8]; - snprintf(ch, 8, "%02X%s", md[j], (j % 2 ? " " : "")); + snprintf(ch, 8, "%02X%s", md[i], (i % 2 ? " " : "")); safe_strcat(s, l, ch); } } @@ -604,14 +603,13 @@ static bool check_certificate_cache(X509 *peercert) unsigned char peermd[EVP_MAX_MD_SIZE]; unsigned int peermdlen; X509 *cert = NULL; - int i; if (!X509_digest(peercert, EVP_sha256(), peermd, &peermdlen) || !SslSessionCerts) { return false; } - for (i = sk_X509_num(SslSessionCerts); i-- > 0;) + for (int i = sk_X509_num(SslSessionCerts); i-- > 0;) { cert = sk_X509_value(SslSessionCerts, i); if (compare_certificates(cert, peercert, peermd, peermdlen)) @@ -666,7 +664,7 @@ static int check_certificate_file(X509 *peercert) */ static int check_host(X509 *x509cert, const char *hostname, char *err, size_t errlen) { - int i, rc = 0; + int rc = 0; /* hostname in ASCII format: */ char *hostname_ascii = NULL; /* needed to get the common name: */ @@ -697,7 +695,7 @@ static int check_host(X509 *x509cert, const char *hostname, char *err, size_t er if ((subj_alt_names = X509_get_ext_d2i(x509cert, NID_subject_alt_name, NULL, NULL))) { subj_alt_names_count = sk_GENERAL_NAME_num(subj_alt_names); - for (i = 0; i < subj_alt_names_count; i++) + for (int i = 0; i < subj_alt_names_count; i++) { subj_alt_name = sk_GENERAL_NAME_value(subj_alt_names, i); if (subj_alt_name->type == GEN_DNS) @@ -797,7 +795,6 @@ static int interactive_check_cert(X509 *cert, int idx, int len, SSL *ssl, int al char title[STRING]; struct Menu *menu = mutt_new_menu(MENU_GENERIC); int done, row; - unsigned u; FILE *fp = NULL; int allow_skip = 0; @@ -812,7 +809,7 @@ static int interactive_check_cert(X509 *cert, int idx, int len, SSL *ssl, int al strfcpy(menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING); row++; x509_subject = X509_get_subject_name(cert); - for (u = 0; u < mutt_array_size(part); u++) + for (unsigned int u = 0; u < mutt_array_size(part); u++) snprintf(menu->dialog[row++], SHORT_STRING, " %s", x509_get_part(x509_subject, part[u])); @@ -820,7 +817,7 @@ static int interactive_check_cert(X509 *cert, int idx, int len, SSL *ssl, int al strfcpy(menu->dialog[row], _("This certificate was issued by:"), SHORT_STRING); row++; x509_issuer = X509_get_issuer_name(cert); - for (u = 0; u < mutt_array_size(part); u++) + for (unsigned int u = 0; u < mutt_array_size(part); u++) snprintf(menu->dialog[row++], SHORT_STRING, " %s", x509_get_part(x509_issuer, part[u])); diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index 1ea0cda032b..d4d44aae022 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -219,7 +219,6 @@ static void tls_fingerprint(gnutls_digest_algorithm_t algo, char *s, int l, { unsigned char md[36]; size_t n; - int j; n = 36; @@ -229,10 +228,10 @@ static void tls_fingerprint(gnutls_digest_algorithm_t algo, char *s, int l, } else { - for (j = 0; j < (int) n; j++) + for (int i = 0; i < (int) n; i++) { char ch[8]; - snprintf(ch, 8, "%02X%s", md[j], (j % 2 ? " " : "")); + snprintf(ch, 8, "%02X%s", md[i], (i % 2 ? " " : "")); safe_strcat(s, l, ch); } s[2 * n + n / 2 - 1] = '\0'; /* don't want trailing space */ @@ -525,7 +524,7 @@ static int tls_check_one_certificate(const gnutls_datum_t *certdata, char title[STRING]; FILE *fp = NULL; gnutls_datum_t pemdata; - int i, row, done, ret; + int row, done, ret; if (!tls_check_preauth(certdata, certstat, hostname, idx, &certerr, &savedcert)) return 1; @@ -561,7 +560,7 @@ static int tls_check_one_certificate(const gnutls_datum_t *certdata, menu = mutt_new_menu(MENU_GENERIC); menu->max = 25; menu->dialog = safe_calloc(1, menu->max * sizeof(char *)); - for (i = 0; i < menu->max; i++) + for (int i = 0; i < menu->max; i++) menu->dialog[i] = safe_calloc(1, SHORT_STRING * sizeof(char)); mutt_push_current_menu(menu); @@ -793,7 +792,7 @@ static int tls_check_certificate(struct Connection *conn) const gnutls_datum_t *cert_list = NULL; unsigned int cert_list_size = 0; gnutls_certificate_status_t certstat; - int certerr, i, preauthrc, savedcert, rc = 0; + int certerr, preauthrc, savedcert, rc = 0; int rcpeer = -1; /* the result of tls_check_preauth() on the peer's EE cert */ if (gnutls_auth_get_type(state) != GNUTLS_CRD_CERTIFICATE) @@ -817,7 +816,7 @@ static int tls_check_certificate(struct Connection *conn) * from most specific to least checking these. If we see a saved certificate, * its status short-circuits the remaining checks. */ preauthrc = 0; - for (i = 0; i < cert_list_size; i++) + for (int i = 0; i < cert_list_size; i++) { rc = tls_check_preauth(&cert_list[i], certstat, conn->account.host, i, &certerr, &savedcert); @@ -840,7 +839,7 @@ static int tls_check_certificate(struct Connection *conn) } /* then check interactively, starting from chain root */ - for (i = cert_list_size - 1; i >= 0; i--) + for (int i = cert_list_size - 1; i >= 0; i--) { rc = tls_check_one_certificate(&cert_list[i], certstat, conn->account.host, i, cert_list_size); diff --git a/muttlib.c b/muttlib.c index 1643a41298a..cedd6635da5 100644 --- a/muttlib.c +++ b/muttlib.c @@ -810,11 +810,9 @@ void mutt_save_path(char *d, size_t dsize, struct Address *a) void mutt_safe_path(char *s, size_t l, struct Address *a) { - char *p = NULL; - mutt_save_path(s, l, a); - for (p = s; *p; p++) - if (*p == '/' || ISSPACE(*p) || !IsPrint((unsigned char) *p)) + for (char *p = s; *p; p++) + if ((*p == '/') || ISSPACE(*p) || !IsPrint((unsigned char) *p)) *p = '_'; } @@ -832,7 +830,7 @@ char *mutt_apply_replace(char *dbuf, size_t dlen, char *sbuf, struct ReplaceList static char twinbuf[2][LONG_STRING]; int switcher = 0; char *p = NULL; - int i, n; + int n; size_t cpysize, tlen; char *src = NULL, *dst = NULL; @@ -893,7 +891,7 @@ char *mutt_apply_replace(char *dbuf, size_t dlen, char *sbuf, struct ReplaceList n = strtoul(p, &p, 10); /* get subst number */ while (isdigit((unsigned char) *p)) /* skip subst token */ p++; - for (i = pmatch[n].rm_so; + for (int i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < LONG_STRING - 1); i++) dst[tlen++] = src[i]; } @@ -985,8 +983,6 @@ void mutt_expando_format(char *dest, size_t destlen, size_t col, int cols, /* Iterate expansions across successive arguments */ do { - char *p = NULL; - /* Extract the command name and copy to command line */ mutt_debug(3, "fmtpipe +++: %s\n", srcbuf->dptr); if (word->data) @@ -996,7 +992,7 @@ void mutt_expando_format(char *dest, size_t destlen, size_t col, int cols, mutt_buffer_addch(command, '\''); mutt_expando_format(buf, sizeof(buf), 0, cols, word->data, callback, data, flags | MUTT_FORMAT_NOFILTER); - for (p = buf; p && *p; p++) + for (char *p = buf; p && *p; p++) { if (*p == '\'') /* shell quoting doesn't permit escaping a single quote within diff --git a/mx.c b/mx.c index 7cb0a3ce51e..a0dbdc62326 100644 --- a/mx.c +++ b/mx.c @@ -987,7 +987,7 @@ void mx_update_tables(struct Context *ctx, int committing) */ int mx_sync_mailbox(struct Context *ctx, int *index_hint) { - int rc, i; + int rc; int purge = 1; int msgcount, deleted; @@ -1032,7 +1032,7 @@ int mx_sync_mailbox(struct Context *ctx, int *index_hint) /* let IMAP servers hold on to D flags */ if (ctx->magic != MUTT_IMAP) { - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) { ctx->hdrs[i]->deleted = false; ctx->hdrs[i]->purge = false; diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 252706db512..252adea6135 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -579,15 +579,14 @@ int crypt_query(struct Body *m) if (m->type == TYPEMULTIPART || m->type == TYPEMESSAGE) { - struct Body *p = NULL; int u, v, w; u = m->parts ? 0xffffffff : 0; /* Bits set in all parts */ w = 0; /* Bits set in any part */ - for (p = m->parts; p; p = p->next) + for (struct Body *b = m->parts; b; b = b->next) { - v = crypt_query(p); + v = crypt_query(b); u &= v; w |= v; } @@ -684,7 +683,6 @@ void convert_to_7bit(struct Body *a) void crypt_extract_keys_from_messages(struct Header *h) { - int i; char tempfname[_POSIX_PATH_MAX], *mbox = NULL; struct Address *tmp = NULL; FILE *fpout = NULL; @@ -704,7 +702,7 @@ void crypt_extract_keys_from_messages(struct Header *h) if (!h) { - for (i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->vcount; i++) { if (Context->hdrs[Context->v2r[i]]->tagged) { @@ -934,7 +932,6 @@ int mutt_signed_handler(struct Body *a, struct State *s) struct Body *b = a; struct Body **signatures = NULL; int sigcnt = 0; - int i; bool goodsig = true; int rc = 0; @@ -995,7 +992,7 @@ int mutt_signed_handler(struct Body *a, struct State *s) mutt_mktemp(tempfile, sizeof(tempfile)); if (crypt_write_signed(a, s, tempfile) == 0) { - for (i = 0; i < sigcnt; i++) + for (int i = 0; i < sigcnt; i++) { if ((WithCrypto & APPLICATION_PGP) && signatures[i]->type == TYPEAPPLICATION && (mutt_strcasecmp(signatures[i]->subtype, "pgp-signature") == 0)) diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index de3e32d53df..bf7c4329fce 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -594,7 +594,7 @@ static gpgme_data_t file_to_data_object(FILE *fp, long offset, long length) static int data_object_to_stream(gpgme_data_t data, FILE *fp) { int err; - char buf[4096], *p = NULL; + char buf[4096]; ssize_t nread; err = ((gpgme_data_seek(data, 0, SEEK_SET) == -1) ? gpgme_error_from_errno(errno) : 0); @@ -608,7 +608,7 @@ static int data_object_to_stream(gpgme_data_t data, FILE *fp) { /* fixme: we are not really converting CRLF to LF but just skipping CR. Doing it correctly needs a more complex logic */ - for (p = buf; nread; p++, nread--) + for (char *p = buf; nread; p++, nread--) { if (*p != '\r') putc(*p, fp); @@ -1448,7 +1448,6 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, { int msgwid; gpgme_user_id_t uids = NULL; - int i; bool aka = false; state_puts(msg, s); @@ -1465,7 +1464,7 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, msgwid = mutt_strwidth(msg) - mutt_strwidth(_("aka: ")) + 1; if (msgwid < 0) msgwid = 0; - for (i = 0; i < msgwid; i++) + for (int i = 0; i < msgwid; i++) state_puts(" ", s); state_puts(_("aka: "), s); } @@ -1489,7 +1488,7 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, msgwid = mutt_strwidth(msg) - mutt_strwidth(_("created: ")) + 1; if (msgwid < 0) msgwid = 0; - for (i = 0; i < msgwid; i++) + for (int i = 0; i < msgwid; i++) state_puts(" ", s); state_puts(_("created: "), s); print_time(sig->timestamp, s); @@ -3373,7 +3372,6 @@ static struct DnArray *parse_dn(const char *string) { struct DnArray *array = NULL; size_t arrayidx, arraysize; - int i; arraysize = 7; /* C,ST,L,O,OU,CN,email */ array = safe_malloc((arraysize + 1) * sizeof(*array)); @@ -3391,7 +3389,7 @@ static struct DnArray *parse_dn(const char *string) arraysize += 5; a2 = safe_malloc((arraysize + 1) * sizeof(*array)); - for (i = 0; i < arrayidx; i++) + for (int i = 0; i < arrayidx; i++) { a2[i].key = array[i].key; a2[i].value = array[i].value; @@ -3417,7 +3415,7 @@ static struct DnArray *parse_dn(const char *string) return array; failure: - for (i = 0; i < arrayidx; i++) + for (int i = 0; i < arrayidx; i++) { FREE(&array[i].key); FREE(&array[i].value); @@ -3436,7 +3434,6 @@ static struct DnArray *parse_dn(const char *string) static void parse_and_print_user_id(FILE *fp, const char *userid) { const char *s = NULL; - int i; if (*userid == '<') { @@ -3456,7 +3453,7 @@ static void parse_and_print_user_id(FILE *fp, const char *userid) else { print_dn_parts(fp, dn); - for (i = 0; dn[i].key; i++) + for (int i = 0; dn[i].key; i++) { FREE(&dn[i].key); FREE(&dn[i].value); @@ -3549,14 +3546,13 @@ static void print_key_info(gpgme_key_t key, FILE *fp) unsigned long aval = 0; const char *delim = NULL; int is_pgp = 0; - int i; gpgme_user_id_t uid = NULL; static int max_header_width = 0; int width; if (!max_header_width) { - for (i = 0; i < KIP_END; i++) + for (int i = 0; i < KIP_END; i++) { KeyInfoPadding[i] = mutt_strlen(_(KeyInfoPrompts[i])); width = mutt_strwidth(_(KeyInfoPrompts[i])); @@ -3564,7 +3560,7 @@ static void print_key_info(gpgme_key_t key, FILE *fp) max_header_width = width; KeyInfoPadding[i] -= width; } - for (i = 0; i < KIP_END; i++) + for (int i = 0; i < KIP_END; i++) KeyInfoPadding[i] += max_header_width; } @@ -3659,7 +3655,7 @@ static void print_key_info(gpgme_key_t key, FILE *fp) fprintf(fp, "%*s", KeyInfoPadding[KIP_FINGERPRINT], _(KeyInfoPrompts[KIP_FINGERPRINT])); if (is_pgp && strlen(s) == 40) { - for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) + for (int i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) { putc(*s, fp); putc(s[1], fp); @@ -3672,7 +3668,7 @@ static void print_key_info(gpgme_key_t key, FILE *fp) } else { - for (i = 0; *s && s[1] && s[2]; s += 2, i++) + for (int i = 0; *s && s[1] && s[2]; s += 2, i++) { putc(*s, fp); putc(s[1], fp); diff --git a/newsrc.c b/newsrc.c index 4874cbe0891..69dedfe0f7f 100644 --- a/newsrc.c +++ b/newsrc.c @@ -444,7 +444,6 @@ int nntp_newsrc_update(struct NntpServer *nserv) for (unsigned int i = 0; i < nserv->groups_num; i++) { struct NntpData *nntp_data = nserv->groups_list[i]; - unsigned int n; if (!nntp_data || !nntp_data->newsrc_ent) continue; @@ -460,20 +459,20 @@ int nntp_newsrc_update(struct NntpServer *nserv) off += strlen(buf + off); /* write entries */ - for (n = 0; n < nntp_data->newsrc_len; n++) + for (unsigned int i = 0; i < nntp_data->newsrc_len; i++) { if (off + LONG_STRING > buflen) { buflen *= 2; safe_realloc(&buf, buflen); } - if (n) + if (i) buf[off++] = ','; - if (nntp_data->newsrc_ent[n].first == nntp_data->newsrc_ent[n].last) - snprintf(buf + off, buflen - off, "%d", nntp_data->newsrc_ent[n].first); - else if (nntp_data->newsrc_ent[n].first < nntp_data->newsrc_ent[n].last) + if (nntp_data->newsrc_ent[i].first == nntp_data->newsrc_ent[i].last) + snprintf(buf + off, buflen - off, "%d", nntp_data->newsrc_ent[i].first); + else if (nntp_data->newsrc_ent[i].first < nntp_data->newsrc_ent[i].last) snprintf(buf + off, buflen - off, "%d-%d", - nntp_data->newsrc_ent[n].first, nntp_data->newsrc_ent[n].last); + nntp_data->newsrc_ent[i].first, nntp_data->newsrc_ent[i].last); off += strlen(buf + off); } buf[off++] = '\n'; @@ -1288,9 +1287,9 @@ void nntp_buffy(char *buf, size_t len) if (Context && Context->magic == MUTT_NNTP && (mutt_strcmp(nntp_data->group, ((struct NntpData *) Context->data)->group) == 0)) { - unsigned int j, unread = 0; + unsigned int unread = 0; - for (j = 0; j < Context->msgcount; j++) + for (unsigned int j = 0; j < Context->msgcount; j++) if (!Context->hdrs[j]->read && !Context->hdrs[j]->deleted) unread++; if (!unread) diff --git a/pager.c b/pager.c index ee61b2f2f20..2b496590baa 100644 --- a/pager.c +++ b/pager.c @@ -226,7 +226,7 @@ static void resolve_color(struct Line *line_info, int n, int cnt, int flags, int color; /* final color */ static int last_color; /* last color set */ bool search = false; - int i, m; + int m; if (!cnt) last_color = -1; /* force attrset() */ @@ -270,7 +270,7 @@ static void resolve_color(struct Line *line_info, int n, int cnt, int flags, color = def_color; if (flags & MUTT_SHOWCOLOR) { - for (i = 0; i < line_info[m].chunks; i++) + for (int i = 0; i < line_info[m].chunks; i++) { /* we assume the chunks are sorted */ if (cnt > (line_info[m].syntax)[i].last) @@ -289,7 +289,7 @@ static void resolve_color(struct Line *line_info, int n, int cnt, int flags, if (flags & MUTT_SEARCH) { - for (i = 0; i < line_info[m].search_cnt; i++) + for (int i = 0; i < line_info[m].search_cnt; i++) { if (cnt > (line_info[m].search)[i].last) continue; diff --git a/parameter.c b/parameter.c index 8d234614165..3f34267e1ae 100644 --- a/parameter.c +++ b/parameter.c @@ -76,9 +76,7 @@ void mutt_set_parameter(const char *attribute, const char *value, struct Paramet void mutt_delete_parameter(const char *attribute, struct Parameter **p) { - struct Parameter *q = NULL; - - for (q = *p; q; p = &q->next, q = q->next) + for (struct Parameter *q = *p; q; p = &q->next, q = q->next) { if (mutt_strcasecmp(attribute, q->attribute) == 0) { diff --git a/pattern.c b/pattern.c index f467640215c..2aa06eb95bc 100644 --- a/pattern.c +++ b/pattern.c @@ -1379,12 +1379,11 @@ static int perform_or(struct Pattern *pat, enum PatternExecFlag flags, static int match_adrlist(struct Pattern *pat, int match_personal, int n, ...) { va_list ap; - struct Address *a = NULL; va_start(ap, n); for (; n; n--) { - for (a = va_arg(ap, struct Address *); a; a = a->next) + for (struct Address *a = va_arg(ap, struct Address *); a; a = a->next) { if (pat->alladdr ^ ((!pat->isalias || alias_reverse_lookup(a)) && ((a->mailbox && !patmatch(pat, a->mailbox)) || @@ -1767,9 +1766,8 @@ void mutt_check_simple(char *s, size_t len, const char *simple) { char tmp[LONG_STRING]; bool do_simple = true; - char *p = NULL; - for (p = s; p && *p; p++) + for (char *p = s; p && *p; p++) { if (*p == '\\' && *(p + 1)) p++; @@ -1994,7 +1992,6 @@ int mutt_pattern_func(int op, char *prompt) int mutt_search_command(int cur, int op) { - int i, j; char buf[STRING]; char temp[LONG_STRING]; int incr; @@ -2045,7 +2042,7 @@ int mutt_search_command(int cur, int op) if (option(OPT_SEARCH_INVALID)) { - for (i = 0; i < Context->msgcount; i++) + for (int i = 0; i < Context->msgcount; i++) Context->hdrs[i]->searched = false; #ifdef USE_IMAP if (Context->magic == MUTT_IMAP && imap_search(Context, SearchPattern) < 0) @@ -2061,7 +2058,7 @@ int mutt_search_command(int cur, int op) mutt_progress_init(&progress, _("Searching..."), MUTT_PROGRESS_MSG, ReadInc, Context->vcount); - for (i = cur + incr, j = 0; j != Context->vcount; j++) + for (int i = cur + incr, j = 0; j != Context->vcount; j++) { mutt_progress_update(&progress, j, -1); if (i > Context->vcount - 1) diff --git a/pgpewrap.c b/pgpewrap.c index da7d30cce30..8b8526a7a62 100644 --- a/pgpewrap.c +++ b/pgpewrap.c @@ -22,7 +22,6 @@ static void print_usage(const char *progname) int main(int argc, char **argv) { char **opts = NULL, **opt = NULL, *pfx = NULL; - int i; if (argc < 2) { @@ -40,7 +39,7 @@ int main(int argc, char **argv) *opt++ = argv[1]; pfx = NULL; - for (i = 2; i < argc;) + for (int i = 2; i < argc;) { if (strcmp(argv[i], "--") == 0) { diff --git a/pgppubring.c b/pgppubring.c index 26a26eee7e6..3272ad0d614 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -425,7 +425,6 @@ static int pgp_parse_pgp2_sig(unsigned char *buff, size_t l, unsigned long signerid1; unsigned long signerid2; size_t j; - int i; if (l < 22) return -1; @@ -434,14 +433,14 @@ static int pgp_parse_pgp2_sig(unsigned char *buff, size_t l, sigtype = buff[j++]; sig_gen_time = 0; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) sig_gen_time = (sig_gen_time << 8) + buff[j++]; signerid1 = signerid2 = 0; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) signerid1 = (signerid1 << 8) + buff[j++]; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) signerid2 = (signerid2 << 8) + buff[j++]; if (sigtype == 0x20 || sigtype == 0x28) @@ -469,7 +468,6 @@ static int pgp_parse_pgp3_sig(unsigned char *buff, size_t l, unsigned long signerid2 = 0; size_t ml; size_t j; - int i; short have_critical_spks = 0; if (l < 7) @@ -520,7 +518,7 @@ static int pgp_parse_pgp3_sig(unsigned char *buff, size_t l, if (skl < 4) break; sig_gen_time = 0; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) sig_gen_time = (sig_gen_time << 8) + buff[j++]; break; @@ -530,7 +528,7 @@ static int pgp_parse_pgp3_sig(unsigned char *buff, size_t l, if (skl < 4) break; validity = 0; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) validity = (validity << 8) + buff[j++]; break; } @@ -539,7 +537,7 @@ static int pgp_parse_pgp3_sig(unsigned char *buff, size_t l, if (skl < 4) break; key_validity = 0; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) key_validity = (key_validity << 8) + buff[j++]; break; } @@ -548,9 +546,9 @@ static int pgp_parse_pgp3_sig(unsigned char *buff, size_t l, if (skl < 8) break; signerid2 = signerid1 = 0; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) signerid1 = (signerid1 << 8) + buff[j++]; - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) signerid2 = (signerid2 << 8) + buff[j++]; break; diff --git a/pop_lib.c b/pop_lib.c index 4f9937ab692..19d446ec483 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -623,12 +623,10 @@ int pop_reconnect(struct Context *ctx) ret = pop_open_connection(pop_data); if (ret == 0) { - int i; - mutt_progress_init(&progressbar, _("Verifying message indexes..."), MUTT_PROGRESS_SIZE, NetInc, 0); - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) ctx->hdrs[i]->refno = -1; ret = pop_fetch_data(pop_data, "UIDL\r\n", &progressbar, check_uidl, ctx); diff --git a/recvattach.c b/recvattach.c index 61850e27c01..8ddd7e9c4a0 100644 --- a/recvattach.c +++ b/recvattach.c @@ -100,11 +100,11 @@ void mutt_update_tree(struct AttachCtx *actx) { char buf[STRING]; char *s = NULL; - int rindex, vindex; + int rindex; mutt_update_v2r(actx); - for (vindex = 0; vindex < actx->vcount; vindex++) + for (int vindex = 0; vindex < actx->vcount; vindex++) { rindex = actx->v2r[vindex]; actx->idx[rindex]->num = vindex; @@ -512,13 +512,13 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, { char buf[_POSIX_PATH_MAX], tfile[_POSIX_PATH_MAX]; char *directory = NULL; - int i, rc = 1; + int rc = 1; int last = menu ? menu->current : -1; FILE *fpout = NULL; buf[0] = 0; - for (i = 0; !tag || i < actx->idxlen; i++) + for (int i = 0; !tag || i < actx->idxlen; i++) { if (tag) { @@ -656,9 +656,7 @@ static void pipe_attachment(FILE *fp, struct Body *b, struct State *state) static void pipe_attachment_list(char *command, struct AttachCtx *actx, FILE *fp, bool tag, struct Body *top, bool filter, struct State *state) { - int i; - - for (i = 0; !tag || i < actx->idxlen; i++) + for (int i = 0; !tag || i < actx->idxlen; i++) { if (tag) { @@ -819,13 +817,11 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru static void recvattach_extract_pgp_keys(struct AttachCtx *actx, struct Menu *menu) { - int i; - if (!menu->tagprefix) crypt_pgp_extract_keys_from_attachment_list(CURATTACH->fp, 0, CURATTACH->content); else { - for (i = 0; i < actx->idxlen; i++) + for (int i = 0; i < actx->idxlen; i++) if (actx->idx[i]->content->tagged) crypt_pgp_extract_keys_from_attachment_list(actx->idx[i]->fp, 0, actx->idx[i]->content); @@ -834,13 +830,13 @@ static void recvattach_extract_pgp_keys(struct AttachCtx *actx, struct Menu *men static int recvattach_pgp_check_traditional(struct AttachCtx *actx, struct Menu *menu) { - int i, rv = 0; + int rv = 0; if (!menu->tagprefix) rv = crypt_pgp_check_traditional(CURATTACH->fp, CURATTACH->content, 1); else { - for (i = 0; i < actx->idxlen; i++) + for (int i = 0; i < actx->idxlen; i++) if (actx->idx[i]->content->tagged) rv = rv || crypt_pgp_check_traditional(actx->idx[i]->fp, actx->idx[i]->content, 1); } @@ -1119,7 +1115,6 @@ void mutt_view_attachments(struct Header *hdr) struct AttachCtx *actx = NULL; int flags = 0; int op = OP_NULL; - int i; /* make sure we have parsed this message */ mutt_parse_mime_message(Context, hdr); @@ -1266,15 +1261,13 @@ void mutt_view_attachments(struct Header *hdr) } else { - int x; - - for (x = 0; x < menu->max; x++) + for (int i = 0; i < menu->max; i++) { - if (actx->idx[x]->content->tagged) + if (actx->idx[i]->content->tagged) { - if (actx->idx[x]->parent_type == TYPEMULTIPART) + if (actx->idx[i]->parent_type == TYPEMULTIPART) { - actx->idx[x]->content->deleted = true; + actx->idx[i]->content->deleted = true; menu->redraw = REDRAW_INDEX; } else @@ -1300,13 +1293,11 @@ void mutt_view_attachments(struct Header *hdr) } else { - int x; - - for (x = 0; x < menu->max; x++) + for (int i = 0; i < menu->max; i++) { - if (actx->idx[x]->content->tagged) + if (actx->idx[i]->content->tagged) { - actx->idx[x]->content->deleted = false; + actx->idx[i]->content->deleted = false; menu->redraw = REDRAW_INDEX; } } @@ -1381,12 +1372,14 @@ void mutt_view_attachments(struct Header *hdr) mx_close_message(Context, &msg); hdr->attach_del = false; - for (i = 0; i < actx->idxlen; i++) + for (int i = 0; i < actx->idxlen; i++) + { if (actx->idx[i]->content && actx->idx[i]->content->deleted) { hdr->attach_del = true; break; } + } if (hdr->attach_del) hdr->changed = true; diff --git a/remailer.c b/remailer.c index 628f98a6c84..8f33d283a9e 100644 --- a/remailer.c +++ b/remailer.c @@ -282,15 +282,13 @@ static void mix_redraw_ce(struct Remailer **type2_list, struct Coord *coords, static void mix_redraw_chain(struct Remailer **type2_list, struct Coord *coords, struct MixChain *chain, int cur) { - int i; - - for (i = MIX_VOFFSET; i < MIX_MAXROW; i++) + for (int i = MIX_VOFFSET; i < MIX_MAXROW; i++) { mutt_window_move(MuttIndexWindow, i, 0); mutt_window_clrtoeol(MuttIndexWindow); } - for (i = 0; i < chain->cl; i++) + for (int i = 0; i < chain->cl; i++) mix_redraw_ce(type2_list, coords, chain, i, i == cur); } @@ -467,7 +465,7 @@ void mix_make_chain(struct ListHead *chainhead) bool loop = true; int op; - int i, j; + int j; char *t = NULL; if (!(type2_list = mix_type2_list(&ttll))) @@ -486,7 +484,7 @@ void mix_make_chain(struct ListHead *chainhead) mutt_list_free(chainhead); /* safety check */ - for (i = 0; i < chain->cl; i++) + for (int i = 0; i < chain->cl; i++) { if (chain->ch[i] >= ttll) chain->ch[i] = 0; @@ -581,7 +579,7 @@ void mix_make_chain(struct ListHead *chainhead) if (chain->cl < MAXMIXES) { chain->cl++; - for (i = chain->cl - 1; i > c_cur; i--) + for (int i = chain->cl - 1; i > c_cur; i--) chain->ch[i] = chain->ch[i - 1]; chain->ch[c_cur] = menu->current; @@ -600,7 +598,7 @@ void mix_make_chain(struct ListHead *chainhead) { chain->cl--; - for (i = c_cur; i < chain->cl; i++) + for (int i = c_cur; i < chain->cl; i++) chain->ch[i] = chain->ch[i + 1]; if (c_cur == chain->cl && c_cur) @@ -645,7 +643,7 @@ void mix_make_chain(struct ListHead *chainhead) if (chain->cl) { - for (i = 0; i < chain->cl; i++) + for (int i = 0; i < chain->cl; i++) { if ((j = chain->ch[i])) t = type2_list[j]->shortname; @@ -668,7 +666,6 @@ int mix_check_message(struct Header *msg) { const char *fqdn = NULL; bool need_hostname = false; - struct Address *p = NULL; if (msg->env->cc || msg->env->bcc) { @@ -682,9 +679,9 @@ int mix_check_message(struct Header *msg) * use_domain won't be respected at this point, hidden_host will. */ - for (p = msg->env->to; p; p = p->next) + for (struct Address *a = msg->env->to; a; a = a->next) { - if (!p->group && strchr(p->mailbox, '@') == NULL) + if (!a->group && strchr(a->mailbox, '@') == NULL) { need_hostname = true; break; diff --git a/rfc2047.c b/rfc2047.c index eaf12042c64..7e3ba8feea4 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -90,9 +90,9 @@ static size_t convert_string(ICONV_CONST char *f, size_t flen, const char *from, int convert_nonmime_string(char **ps) { - const char *c = NULL, *c1 = NULL; + const char *c1 = NULL; - for (c = AssumedCharset; c; c = c1 ? c1 + 1 : 0) + for (const char *c = AssumedCharset; c; c = c1 ? c1 + 1 : 0) { char *u = *ps; char *s = NULL; @@ -130,9 +130,9 @@ char *mutt_choose_charset(const char *fromcode, const char *charsets, char *u, char canonical_buff[LONG_STRING]; char *e = NULL, *tocode = NULL; size_t elen = 0, bestn = 0; - const char *p = NULL, *q = NULL; + const char *q = NULL; - for (p = charsets; p; p = q ? q + 1 : 0) + for (const char *p = charsets; p; p = q ? q + 1 : 0) { char *s = NULL, *t = NULL; size_t slen, n; @@ -203,11 +203,11 @@ static size_t b_encoder(char *s, ICONV_CONST char *d, size_t dlen, const char *t while (dlen) { char encoded[11]; - size_t ret, i; + size_t ret; size_t in_len = MIN(3, dlen); ret = mutt_to_base64(encoded, d, in_len, sizeof(encoded)); - for (i = 0; i < ret; i++) + for (size_t i = 0; i < ret; i++) *s++ = encoded[i]; dlen -= in_len; @@ -273,7 +273,7 @@ static size_t try_block(ICONV_CONST char *d, size_t dlen, const char *fromcode, char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; iconv_t cd; ICONV_CONST char *ib = NULL; - char *ob = NULL, *p = NULL; + char *ob = NULL; size_t ibl, obl; int count, len, len_b, len_q; @@ -304,7 +304,7 @@ static size_t try_block(ICONV_CONST char *d, size_t dlen, const char *fromcode, } count = 0; - for (p = buf1; p < ob; p++) + for (char *p = buf1; p < ob; p++) { unsigned char c = *p; assert(strchr(MimeSpecials, '?')); diff --git a/score.c b/score.c index 98362a24d98..56e698ed120 100644 --- a/score.c +++ b/score.c @@ -51,8 +51,6 @@ static struct Score *ScoreList = NULL; void mutt_check_rescore(struct Context *ctx) { - int i; - if (option(OPT_NEED_RESCORE) && option(OPT_SCORE)) { if ((Sort & SORT_MASK) == SORT_SCORE || (SortAux & SORT_MASK) == SORT_SCORE) @@ -66,7 +64,7 @@ void mutt_check_rescore(struct Context *ctx) mutt_set_menu_redraw_full(MENU_MAIN); mutt_set_menu_redraw_full(MENU_PAGER); - for (i = 0; ctx && i < ctx->msgcount; i++) + for (int i = 0; ctx && i < ctx->msgcount; i++) { mutt_score_message(ctx, ctx->hdrs[i], 1); ctx->hdrs[i]->pair = 0; diff --git a/send.c b/send.c index 3b7cb8ac5c5..f71c2b94695 100644 --- a/send.c +++ b/send.c @@ -761,13 +761,12 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, struct Header *cur, int flags) { struct Envelope *curenv = NULL; - int i = 0; bool tag = false; if (!cur) { tag = true; - for (i = 0; i < ctx->vcount; i++) + for (int i = 0; i < ctx->vcount; i++) if (ctx->hdrs[ctx->v2r[i]]->tagged) { cur = ctx->hdrs[ctx->v2r[i]]; @@ -805,7 +804,7 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, { struct Header *h = NULL; - for (i = 0; i < ctx->vcount; i++) + for (int i = 0; i < ctx->vcount; i++) { h = ctx->hdrs[ctx->v2r[i]]; if (h->tagged && mutt_fetch_recips(env, h->env, flags) == -1) @@ -1148,9 +1147,7 @@ static int send_message(struct Header *msg) */ void mutt_encode_descriptions(struct Body *b, short recurse) { - struct Body *t = NULL; - - for (t = b; t; t = t->next) + for (struct Body *t = b; t; t = t->next) { if (t->description) { @@ -1166,9 +1163,7 @@ void mutt_encode_descriptions(struct Body *b, short recurse) */ static void decode_descriptions(struct Body *b) { - struct Body *t = NULL; - - for (t = b; t; t = t->next) + for (struct Body *t = b; t; t = t->next) { if (t->description) { diff --git a/sendlib.c b/sendlib.c index da896aae43d..ef1368a0584 100644 --- a/sendlib.c +++ b/sendlib.c @@ -315,7 +315,6 @@ static void encode_8bit(FGETCONV *fc, FILE *fout, int istext) int mutt_write_mime_header(struct Body *a, FILE *f) { - struct Parameter *p = NULL; char buffer[STRING]; char *t = NULL; char *fn = NULL; @@ -329,7 +328,7 @@ int mutt_write_mime_header(struct Body *a, FILE *f) { len = 25 + mutt_strlen(a->subtype); /* approximate len. of content-type */ - for (p = a->parameter; p; p = p->next) + for (struct Parameter *p = a->parameter; p; p = p->next) { char *tmp = NULL; @@ -432,7 +431,6 @@ int mutt_write_mime_body(struct Body *a, FILE *f) char *p, boundary[SHORT_STRING]; char send_charset[SHORT_STRING]; FILE *fpin = NULL; - struct Body *t = NULL; FGETCONV *fc = NULL; if (a->type == TYPEMULTIPART) @@ -446,7 +444,7 @@ int mutt_write_mime_body(struct Body *a, FILE *f) } strfcpy(boundary, p, sizeof(boundary)); - for (t = a->parts; t; t = t->next) + for (struct Body *t = a->parts; t; t = t->next) { fprintf(f, "\n--%s\n", boundary); if (mutt_write_mime_header(t, f) == -1) @@ -685,7 +683,6 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, ICONV_CONST char *ib = NULL, *ub = NULL; char *ob = NULL; size_t ibl, obl, ubl, ubl1, n, ret; - int i; struct Content *infos = NULL; struct ContentState *states = NULL; size_t *score = NULL; @@ -699,7 +696,8 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, states = safe_calloc(ncodes, sizeof(struct ContentState)); infos = safe_calloc(ncodes, sizeof(struct Content)); - for (i = 0; i < ncodes; i++) + for (int i = 0; i < ncodes; i++) + { if (mutt_strcasecmp(tocodes[i], "utf-8") != 0) cd[i] = mutt_iconv_open(tocodes[i], "utf-8", 0); else @@ -708,6 +706,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, cd[i] = (iconv_t)(-1); score[i] = (size_t)(-1); } + } rewind(file); ibl = 0; @@ -732,7 +731,8 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, ubl1 = ob - bufu; /* Convert from UTF-8 */ - for (i = 0; i < ncodes; i++) + for (int i = 0; i < ncodes; i++) + { if (cd[i] != (iconv_t)(-1) && score[i] != (size_t)(-1)) { ub = bufu; @@ -754,6 +754,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, else if (cd[i] == (iconv_t)(-1) && score[i] == (size_t)(-1)) /* Special case for conversion to UTF-8 */ update_content_info(&infos[i], &states[i], bufu, ubl1); + } if (ibl) /* Save unused input */ @@ -769,7 +770,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, { /* Find best score */ ret = (size_t)(-1); - for (i = 0; i < ncodes; i++) + for (int i = 0; i < ncodes; i++) { if (cd[i] == (iconv_t)(-1) && score[i] == (size_t)(-1)) { @@ -795,7 +796,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, } } - for (i = 0; i < ncodes; i++) + for (int i = 0; i < ncodes; i++) if (cd[i] != (iconv_t)(-1)) iconv_close(cd[i]); @@ -2726,7 +2727,7 @@ void mutt_unprepare_envelope(struct Envelope *env) static int _mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to, const char *resent_from, struct Address *env_from) { - int i, ret = 0; + int ret = 0; FILE *f = NULL; char date[SHORT_STRING], tempfile[_POSIX_PATH_MAX]; struct Message *msg = NULL; @@ -2734,7 +2735,7 @@ static int _mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to, if (!h) { /* Try to bounce each message out, aborting if we get any failures. */ - for (i = 0; i < Context->msgcount; i++) + for (int i = 0; i < Context->msgcount; i++) if (Context->hdrs[i]->tagged) ret |= _mutt_bounce_message(fp, Context->hdrs[i], to, resent_from, env_from); return ret; diff --git a/sidebar.c b/sidebar.c index d0eabfd5cb4..3eda364afcf 100644 --- a/sidebar.c +++ b/sidebar.c @@ -680,7 +680,6 @@ static int draw_divider(int num_rows, int num_cols) if ((num_rows < 1) || (num_cols < 1)) return 0; - int i; int delim_len; enum DivType altchar = SB_DIV_UTF8; @@ -711,7 +710,7 @@ static int draw_divider(int num_rows, int num_cols) } else if (SidebarDividerChar) { - for (i = 0; i < delim_len; i++) + for (int i = 0; i < delim_len; i++) { if (SidebarDividerChar[i] & ~0x7F) /* high-bit is set */ { @@ -730,7 +729,7 @@ static int draw_divider(int num_rows, int num_cols) int col = option(OPT_SIDEBAR_ON_RIGHT) ? 0 : (SidebarWidth - delim_len); - for (i = 0; i < num_rows; i++) + for (int i = 0; i < num_rows; i++) { mutt_window_move(MuttSidebarWindow, i, col); @@ -771,8 +770,7 @@ static void fill_empty_space(int first_row, int num_rows, int div_width, int num { mutt_window_move(MuttSidebarWindow, first_row + r, div_width); - int i; - for (i = 0; i < num_cols; i++) + for (int i = 0; i < num_cols; i++) addch(' '); } } @@ -872,12 +870,11 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) /* calculate depth of current folder and generate its display name with indented spaces */ int sidebar_folder_depth = 0; char *sidebar_folder_name = NULL; - int i; if (option(OPT_SIDEBAR_SHORT_PATH)) { /* disregard a trailing separator, so strlen() - 2 */ sidebar_folder_name = b->path; - for (i = mutt_strlen(sidebar_folder_name) - 2; i >= 0; i--) + for (int i = mutt_strlen(sidebar_folder_name) - 2; i >= 0; i--) { if (SidebarDelimChars && strchr(SidebarDelimChars, sidebar_folder_name[i])) { @@ -899,7 +896,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) int lastsep = 0; tmp_folder_name = b->path + maildirlen + 1; int tmplen = (int) mutt_strlen(tmp_folder_name) - 1; - for (i = 0; i < tmplen; i++) + for (int i = 0; i < tmplen; i++) { if (SidebarDelimChars && strchr(SidebarDelimChars, tmp_folder_name[i])) { @@ -915,7 +912,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) sidebar_folder_depth * mutt_strlen(SidebarIndentString) + 1; sidebar_folder_name = safe_malloc(sfn_len); sidebar_folder_name[0] = 0; - for (i = 0; i < sidebar_folder_depth; i++) + for (int i = 0; i < sidebar_folder_depth; i++) safe_strcat(sidebar_folder_name, sfn_len, NONULL(SidebarIndentString)); safe_strcat(sidebar_folder_name, sfn_len, tmp_folder_name); } diff --git a/sort.c b/sort.c index 96060dce6ce..2ebb10a06b5 100644 --- a/sort.c +++ b/sort.c @@ -305,7 +305,6 @@ sort_t *mutt_get_sort_func(int method) void mutt_sort_headers(struct Context *ctx, int init) { - int i; struct Header *h = NULL; struct MuttThread *thread = NULL, *top = NULL; sort_t *sortfunc = NULL; @@ -331,7 +330,7 @@ void mutt_sort_headers(struct Context *ctx, int init) if (option(OPT_NEED_RESCORE) && option(OPT_SCORE)) { - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) mutt_score_message(ctx, ctx->hdrs[i], 1); } unset_option(OPT_NEED_RESCORE); @@ -352,7 +351,7 @@ void mutt_sort_headers(struct Context *ctx, int init) subthreads need to be resorted */ if (option(OPT_SORT_SUBTHREADS)) { - i = Sort; + int i = Sort; Sort = SortAux; if (ctx->tree) ctx->tree = mutt_sort_subthreads(ctx->tree, 1); @@ -373,7 +372,7 @@ void mutt_sort_headers(struct Context *ctx, int init) /* adjust the virtual message numbers */ ctx->vcount = 0; - for (i = 0; i < ctx->msgcount; i++) + for (int i = 0; i < ctx->msgcount; i++) { struct Header *cur = ctx->hdrs[i]; if (cur->virtual != -1 || (cur->collapsed && (!ctx->pattern || cur->limited))) diff --git a/thread.c b/thread.c index 7a0fd560b39..ea00edcb62f 100644 --- a/thread.c +++ b/thread.c @@ -1395,7 +1395,6 @@ struct Hash *mutt_make_id_hash(struct Context *ctx) static void clean_references(struct MuttThread *brk, struct MuttThread *cur) { - struct MuttThread *p = NULL; struct ListNode *ref = NULL; bool done = false; @@ -1410,7 +1409,7 @@ static void clean_references(struct MuttThread *brk, struct MuttThread *cur) /* Looking for the first bad reference according to the new threading. * Optimal since NeoMutt stores the references in reverse order, and the * first loop should match immediately for mails respecting RFC2822. */ - for (p = brk; !done && p; p = p->parent) + for (struct MuttThread *p = brk; !done && p; p = p->parent) { for (ref = STAILQ_FIRST(&cur->message->env->references); p->message && ref; ref = STAILQ_NEXT(ref, entries)) @@ -1465,12 +1464,11 @@ static bool link_threads(struct Header *parent, struct Header *child, struct Con int mutt_link_threads(struct Header *cur, struct Header *last, struct Context *ctx) { - int i; bool changed = false; if (!last) { - for (i = 0; i < ctx->vcount; i++) + for (int i = 0; i < ctx->vcount; i++) if (ctx->hdrs[Context->v2r[i]]->tagged) changed |= link_threads(cur, ctx->hdrs[Context->v2r[i]], ctx); } diff --git a/txt2c.c b/txt2c.c index 790d4219019..49e23148446 100644 --- a/txt2c.c +++ b/txt2c.c @@ -26,7 +26,6 @@ static void txt2c(char *sym, FILE *fp) { unsigned char buf[PER_LINE]; - int i; int sz = 0; printf("unsigned char %s[] = {\n", sym); @@ -36,7 +35,7 @@ static void txt2c(char *sym, FILE *fp) if (sz == 0) break; printf("\t"); - for (i = 0; i < sz; i++) + for (int i = 0; i < sz; i++) printf("0x%02x, ", buf[i]); printf("\n"); }