From: Richard Russon Date: Sat, 1 Jun 2019 17:17:30 +0000 (+0100) Subject: reduce scope of variables X-Git-Tag: 2019-10-25~179^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2894e5b8e65e20c2235484d61c89ebc530c40c83;p=neomutt reduce scope of variables --- diff --git a/browser.c b/browser.c index 1ac20d556..a3a803c3f 100644 --- a/browser.c +++ b/browser.c @@ -438,9 +438,9 @@ static const char *folder_format_str(char *buf, size_t buflen, size_t col, int c } case 'F': { - char permission[11]; if (folder->ff->local) { + char permission[11]; snprintf(permission, sizeof(permission), "%c%c%c%c%c%c%c%c%c%c", S_ISDIR(folder->ff->mode) ? 'd' : (S_ISLNK(folder->ff->mode) ? 'l' : '-'), ((folder->ff->mode & S_IRUSR) != 0) ? 'r' : '-', @@ -463,6 +463,7 @@ static const char *folder_format_str(char *buf, size_t buflen, size_t col, int c #ifdef USE_IMAP else if (folder->ff->imap) { + char permission[11]; /* mark folders with subfolders AND mail */ snprintf(permission, sizeof(permission), "IMAP %c", (folder->ff->inferiors && folder->ff->selectable) ? '+' : ' '); diff --git a/doc/makedoc.c b/doc/makedoc.c index 16d05980a..09c2ce540 100644 --- a/doc/makedoc.c +++ b/doc/makedoc.c @@ -716,8 +716,7 @@ static int flush_doc(int docstat, FILE *out) if (docstat & (D_EM | D_BF | D_TT)) docstat = print_it(SP_END_FT, NULL, out, docstat); - docstat = print_it(SP_END_SECT, NULL, out, docstat); - + print_it(SP_END_SECT, NULL, out, docstat); print_it(SP_NEWLINE, NULL, out, 0); fd_recurse--; diff --git a/handler.c b/handler.c index eb3dd10f8..3af352a37 100644 --- a/handler.c +++ b/handler.c @@ -536,7 +536,6 @@ static int autoview_handler(struct Body *a, struct State *s) FILE *fp_in = NULL; FILE *fp_out = NULL; FILE *fp_err = NULL; - int piped = false; pid_t pid; int rc = 0; @@ -553,7 +552,7 @@ static int autoview_handler(struct Body *a, struct State *s) mutt_buffer_strcpy(cmd, entry->command); /* rfc1524_expand_command returns 0 if the file is required */ - piped = mutt_buffer_rfc1524_expand_command(a, mutt_b2s(tempfile), type, cmd); + bool piped = mutt_buffer_rfc1524_expand_command(a, mutt_b2s(tempfile), type, cmd); if (s->flags & MUTT_DISPLAY) { @@ -675,15 +674,15 @@ cleanup: static int text_plain_handler(struct Body *b, struct State *s) { char *buf = NULL; - size_t l = 0, sz = 0; + size_t sz = 0; while ((buf = mutt_file_read_line(buf, &sz, s->fp_in, NULL, 0))) { if ((mutt_str_strcmp(buf, "-- ") != 0) && C_TextFlowed) { - l = mutt_str_strlen(buf); - while ((l > 0) && (buf[l - 1] == ' ')) - buf[--l] = '\0'; + size_t len = mutt_str_strlen(buf); + while ((len > 0) && (buf[len - 1] == ' ')) + buf[--len] = '\0'; } if (s->prefix) state_puts(s->prefix, s); diff --git a/hdrline.c b/hdrline.c index 19a3a5f56..e1af52e1a 100644 --- a/hdrline.c +++ b/hdrline.c @@ -678,7 +678,6 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co /* preprocess $date_format to handle %Z */ { const char *cp = NULL; - struct tm tm = { 0 }; time_t now; int j = 0; @@ -686,7 +685,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co { char *is = NULL; now = time(NULL); - tm = mutt_date_localtime(now); + struct tm tm = mutt_date_localtime(now); now -= (op == '(') ? e->received : e->date_sent; is = (char *) prec; @@ -827,6 +826,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co } *p = '\0'; + struct tm tm; if ((op == '[') || (op == 'D')) tm = mutt_date_localtime(e->date_sent); else if (op == '(') diff --git a/main.c b/main.c index 2805ae14e..b1dce02b7 100644 --- a/main.c +++ b/main.c @@ -342,10 +342,8 @@ static void init_locale(void) textdomain(PACKAGE); #endif #ifndef LOCALES_HACK - const char *p = NULL; /* Do we have a locale definition? */ - if ((p = mutt_str_getenv("LC_ALL")) || (p = mutt_str_getenv("LANG")) || - (p = mutt_str_getenv("LC_CTYPE"))) + if (mutt_str_getenv("LC_ALL") || mutt_str_getenv("LANG") || mutt_str_getenv("LC_CTYPE")) { OptLocales = true; } diff --git a/muttlib.c b/muttlib.c index b4abdb24e..4629df52d 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1257,15 +1257,15 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c } else { - bool tolower = false; - bool nodots = false; + bool to_lower = false; + bool no_dots = false; while ((ch == '_') || (ch == ':')) { if (ch == '_') - tolower = true; + to_lower = true; else if (ch == ':') - nodots = true; + no_dots = true; ch = *src++; } @@ -1274,9 +1274,9 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c src = callback(tmp, sizeof(tmp), col, cols, ch, src, prefix, if_str, else_str, data, flags); - if (tolower) + if (to_lower) mutt_str_strlower(tmp); - if (nodots) + if (no_dots) { char *p = tmp; for (; *p; p++) diff --git a/ncrypt/smime.c b/ncrypt/smime.c index c95de3d63..a0b7d76f4 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -1086,7 +1086,6 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, bool copy, char email[256]; int rc = -1, count = 0; pid_t pid; - size_t len = 0; FILE *fp_err = mutt_file_mkstemp(); if (!fp_err) @@ -1122,7 +1121,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, bool copy, while ((fgets(email, sizeof(email), fp_out))) { - len = mutt_str_strlen(email); + size_t len = mutt_str_strlen(email); if (len && (email[len - 1] == '\n')) email[len - 1] = '\0'; if (mutt_str_startswith(email, mailbox, CASE_IGNORE)) @@ -1153,7 +1152,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, bool copy, rewind(fp_out); while ((fgets(email, sizeof(email), fp_out))) { - len = mutt_str_strlen(email); + size_t len = mutt_str_strlen(email); if (len && (email[len - 1] == '\n')) email[len - 1] = '\0'; (*buffer)[count] = mutt_mem_calloc(mutt_str_strlen(email) + 1, sizeof(char)); diff --git a/nntp/nntp.c b/nntp/nntp.c index bdf880156..969dcadcf 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1594,11 +1594,10 @@ static int check_mailbox(struct Mailbox *m) /* update flags according to .newsrc */ int j = 0; - anum_t anum; for (int i = 0; i < m->msg_count; i++) { bool flagged = false; - anum = nntp_edata_get(m->emails[i])->article_num; + anum_t anum = nntp_edata_get(m->emails[i])->article_num; #ifdef USE_HCACHE /* check hcache for flagged and deleted flags */ @@ -1648,7 +1647,7 @@ static int check_mailbox(struct Mailbox *m) m->msg_count = j; /* restore headers without "deleted" flag */ - for (anum = first; anum <= mdata->last_loaded; anum++) + for (anum_t anum = first; anum <= mdata->last_loaded; anum++) { if (messages[anum - first]) continue; diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index b2c411ae5..b0c5d007d 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -2374,12 +2374,12 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint) struct Progress progress; char *uri = mutt_str_strdup(mutt_b2s(m->pathbuf)); bool changed = false; - char msgbuf[PATH_MAX + 64]; mutt_debug(LL_DEBUG1, "nm: sync start\n"); if (!m->quiet) { + char msgbuf[PATH_MAX + 64]; /* all is in this function so we don't use data->progress here */ snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count); diff --git a/rfc3676.c b/rfc3676.c index fa86e9416..7c17031ae 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -397,7 +397,6 @@ int rfc3676_handler(struct Body *a, struct State *s) void rfc3676_space_stuff(struct Email *e) { int lc = 0; - size_t len = 0; unsigned char c = '\0'; char buf[1024]; char tmpfile[PATH_MAX]; @@ -425,7 +424,7 @@ void rfc3676_space_stuff(struct Email *e) { fputc(' ', fp_out); lc++; - len = mutt_str_strlen(buf); + size_t len = mutt_str_strlen(buf); if (len > 0) { c = buf[len - 1]; diff --git a/test/pattern/comp.c b/test/pattern/comp.c index c550dd124..da1012e32 100644 --- a/test/pattern/comp.c +++ b/test/pattern/comp.c @@ -129,10 +129,8 @@ static int cmp_pattern(struct PatternHead *p1, struct PatternHead *p2) while (!SLIST_EMPTY(&p1_tmp)) { - struct Pattern *l = NULL, *r = NULL; - - l = SLIST_FIRST(&p1_tmp); - r = SLIST_FIRST(&p2_tmp); + struct Pattern *l = SLIST_FIRST(&p1_tmp); + struct Pattern *r = SLIST_FIRST(&p2_tmp); /* if l is NULL then r must be NULL (and vice-versa) */ if ((!l || !r) && !(!l && !r)) diff --git a/test/sha1/mutt_sha1_transform.c b/test/sha1/mutt_sha1_transform.c index 8dd648e35..7db5f9ed1 100644 --- a/test/sha1/mutt_sha1_transform.c +++ b/test/sha1/mutt_sha1_transform.c @@ -30,13 +30,13 @@ void test_mutt_sha1_transform(void) // void mutt_sha1_transform(uint32_t state[5], const unsigned char buffer[64]); { - unsigned char buf[32] = { 0 }; + unsigned char buf[64] = { 0 }; mutt_sha1_transform(NULL, buf); TEST_CHECK_(1, "mutt_sha1_transform(NULL, &buf)"); } { - uint32_t buf[32] = { 0 }; + uint32_t buf[64] = { 0 }; mutt_sha1_transform(buf, NULL); TEST_CHECK_(1, "mutt_sha1_transform(&buf, NULL)"); }