From: Richard Russon Date: Fri, 5 Oct 2018 16:17:42 +0000 (+0100) Subject: cppcheck: reduce variable scope X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf54438f568fd3bb744880d6f481f8b503609108;p=neomutt cppcheck: reduce variable scope --- diff --git a/editmsg.c b/editmsg.c index a7737085f..f892bf2fe 100644 --- a/editmsg.c +++ b/editmsg.c @@ -71,7 +71,6 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Email int of, cf; - struct Context *tmpctx = NULL; struct Message *msg = NULL; FILE *fp = NULL; @@ -84,7 +83,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Email omagic = MboxType; MboxType = MUTT_MBOX; - tmpctx = mx_mbox_open(tmp, MUTT_NEWFOLDER); + struct Context *tmpctx = mx_mbox_open(tmp, MUTT_NEWFOLDER); MboxType = omagic; diff --git a/imap/util.c b/imap/util.c index afab286d6..10391d57f 100644 --- a/imap/util.c +++ b/imap/util.c @@ -222,13 +222,12 @@ void imap_clean_path(char *path, size_t plen) static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapMboxData *mdata) { int first = 1, state = 0; - bool match = false; unsigned int cur_uid = 0, last_uid = 0; unsigned int range_begin = 0, range_end = 0; for (unsigned int msn = 1; msn <= mdata->max_msn + 1; msn++) { - match = false; + bool match = false; if (msn <= mdata->max_msn) { struct Email *cur_header = mdata->msn_index[msn - 1]; @@ -1176,8 +1175,6 @@ struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset) */ int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next) { - char *range_sep; - if (!iter || !next) return -1; @@ -1204,7 +1201,7 @@ int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next) else *(iter->substr_end) = '\0'; - range_sep = strchr(iter->substr_cur, ':'); + char *range_sep = strchr(iter->substr_cur, ':'); if (range_sep) *range_sep++ = '\0'; diff --git a/init.c b/init.c index 9c6118771..d7dba3514 100644 --- a/init.c +++ b/init.c @@ -1191,14 +1191,13 @@ bail: static int parse_ifdef(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { - bool res = false; struct Buffer token = { 0 }; mutt_extract_token(buf, s, 0); /* is the item defined as a variable? */ struct HashElem *he = cs_get_elem(Config, buf->data); - res = (he != NULL); + bool res = (he != NULL); /* is the item a compiled-in feature? */ if (!res) diff --git a/monitor.c b/monitor.c index 7c8ca865e..8e7f72be6 100644 --- a/monitor.c +++ b/monitor.c @@ -386,13 +386,12 @@ int mutt_monitor_poll(void) { MonitorFilesChanged = 1; mutt_debug(3, "file change(s) detected\n"); - int len; char *ptr = buf; const struct inotify_event *event; while (true) { - len = read(INotifyFd, buf, sizeof(buf)); + int len = read(INotifyFd, buf, sizeof(buf)); if (len == -1) { if (errno != EAGAIN) diff --git a/mutt/file.c b/mutt/file.c index 46e92b180..4d3febae3 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -91,11 +91,10 @@ static int mkwrapdir(const char *path, char *newfile, size_t nflen, char *newdir { const char *basename = NULL; char parent[PATH_MAX]; - char *p = NULL; mutt_str_strfcpy(parent, path, sizeof(parent)); - p = strrchr(parent, '/'); + char *p = strrchr(parent, '/'); if (p) { *p = '\0'; diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 2f02b77ae..a507cf669 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -4564,9 +4564,7 @@ static struct CryptKeyInfo *crypt_getkeybyaddr(struct Address *a, if (match) { - struct CryptKeyInfo *tmp = NULL; - - tmp = crypt_copy_key(k); + struct CryptKeyInfo *tmp = crypt_copy_key(k); *matches_endp = tmp; matches_endp = &tmp->next; @@ -4656,11 +4654,9 @@ static struct CryptKeyInfo *crypt_getkeybystr(char *p, short abilities, (ps && (mutt_str_strcasecmp(ps, crypt_short_keyid(k)) == 0)) || mutt_str_stristr(k->uid, p)) { - struct CryptKeyInfo *tmp = NULL; - mutt_debug(5, "match.\n"); - tmp = crypt_copy_key(k); + struct CryptKeyInfo *tmp = crypt_copy_key(k); *matches_endp = tmp; matches_endp = &tmp->next; } diff --git a/ncrypt/pgpinvoke.c b/ncrypt/pgpinvoke.c index bf05cfbe2..3c87e8ca8 100644 --- a/ncrypt/pgpinvoke.c +++ b/ncrypt/pgpinvoke.c @@ -524,12 +524,9 @@ pid_t pgp_invoke_list_keys(FILE **pgpin, FILE **pgpout, FILE **pgperr, int pgpinfd, int pgpoutfd, int pgperrfd, enum PgpRing keyring, struct ListHead *hints) { - struct Buffer *uids = NULL; char quoted[HUGE_STRING]; - pid_t rc; - - uids = mutt_buffer_new(); + struct Buffer *uids = mutt_buffer_new(); mutt_buffer_increase_size(uids, HUGE_STRING); struct ListNode *np = NULL; @@ -541,9 +538,9 @@ pid_t pgp_invoke_list_keys(FILE **pgpin, FILE **pgpout, FILE **pgperr, mutt_buffer_addch(uids, ' '); } - rc = pgp_invoke(pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd, 0, NULL, - NULL, uids->data, - keyring == PGP_SECRING ? PgpListSecringCommand : PgpListPubringCommand); + pid_t rc = pgp_invoke( + pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd, 0, NULL, NULL, uids->data, + keyring == PGP_SECRING ? PgpListSecringCommand : PgpListPubringCommand); mutt_buffer_free(&uids); return rc; diff --git a/pager.c b/pager.c index b0a18fe25..dc443fbdf 100644 --- a/pager.c +++ b/pager.c @@ -836,7 +836,6 @@ int mutt_is_quote_line(char *line, regmatch_t *pmatch) { bool is_quote = false; regmatch_t pmatch_internal[1], smatch[1]; - char c; if (!pmatch) pmatch = pmatch_internal; @@ -847,7 +846,7 @@ int mutt_is_quote_line(char *line, regmatch_t *pmatch) { if (smatch[0].rm_so > 0) { - c = line[smatch[0].rm_so]; + char c = line[smatch[0].rm_so]; line[smatch[0].rm_so] = 0; if (regexec(QuoteRegex->regex, line, 1, pmatch, 0) == 0) diff --git a/remailer.c b/remailer.c index a3d7170a2..82bd992c2 100644 --- a/remailer.c +++ b/remailer.c @@ -820,11 +820,10 @@ int mix_check_message(struct Email *msg) */ int mix_send_message(struct ListHead *chain, const char *tempfile) { - struct Buffer *cmd = NULL; char cd_quoted[STRING]; int i = 0; - cmd = mutt_buffer_new(); + struct Buffer *cmd = mutt_buffer_new(); mutt_buffer_increase_size(cmd, HUGE_STRING); mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, Mixmaster);