]> granicus.if.org Git - neomutt/commitdiff
reduce scope of variables
authorRichard Russon <rich@flatcap.org>
Sat, 1 Jun 2019 17:17:30 +0000 (18:17 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Jun 2019 23:06:49 +0000 (00:06 +0100)
12 files changed:
browser.c
doc/makedoc.c
handler.c
hdrline.c
main.c
muttlib.c
ncrypt/smime.c
nntp/nntp.c
notmuch/mutt_notmuch.c
rfc3676.c
test/pattern/comp.c
test/sha1/mutt_sha1_transform.c

index 1ac20d5563c41893a15d295efeb1e74248b60478..a3a803c3f40592dc652fafcb3a9ae12342fe7ea9 100644 (file)
--- 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) ? '+' : ' ');
index 16d05980a76d62df4236b6b1ed506329dd521d6b..09c2ce540518cf53b57fdb36cb8f002e09ce5d84 100644 (file)
@@ -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--;
index eb3dd10f86cde850478c75d3e69381fce4fb9122..3af352a3775f4d56fd37f47b5dead11e76b4f266 100644 (file)
--- 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);
index 19a3a5f56badbcb0aed8117c883425d76bd24a24..e1af52e1ab39b53ec3b16b1af74733810f1362df 100644 (file)
--- 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 2805ae14efc7cd89d36ae60405ade9b792fe4558..b1dce02b77e232b64bc8192963e4016dca422f52 100644 (file)
--- 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;
   }
index b4abdb24eac5db9e8ada53309acad12de070c8cd..4629df52d5e8acc45280b3350af193c7391f5bc3 100644 (file)
--- 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++)
index c95de3d63dd7c8079eeca9f3933dafc7e9f858b0..a0b7d76f471ce852bc8fbc1e3b5b02808146fa1f 100644 (file)
@@ -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));
index bdf880156e39cc92b5b6318937146936b0afe99c..969dcadcf7140125a9d3ac1aaba28040848f9a6c 100644 (file)
@@ -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;
index b2c411ae583078602eb19c9aab0c4a2af033ed42..b0c5d007dcc13743a02252b0b1076f1ab0d5eacc 100644 (file)
@@ -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);
index fa86e94161559b3270a5c04790503f399aa5cc5b..7c17031ae1cc0f25d35b134c09a374d54f77d19f 100644 (file)
--- 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];
index c550dd12484af570dcde4dc1d1fd3dfaa7954f8e..da1012e32fbce6ccf9a2e3e43aef4503b34f4e99 100644 (file)
@@ -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))
index 8dd648e35150f06ac295bb36db8a6a08309063be..7db5f9ed16709320b877674a1f0de8d82b21b29d 100644 (file)
@@ -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)");
   }