]> granicus.if.org Git - neomutt/commitdiff
tidy ternary operators
authorRichard Russon <rich@flatcap.org>
Wed, 15 May 2019 22:53:37 +0000 (23:53 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 16 May 2019 13:02:46 +0000 (14:02 +0100)
- insert ()s
- expand checks against 0 or '\0'

21 files changed:
conn/sasl.c
copy.c
curs_lib.c
edit.c
email/rfc2047.c
handler.c
hcache/serialize.c
menu.c
mutt/logging.c
mutt/string.c
mutt_account.c
mutt_thread.c
muttlib.c
ncrypt/crypt_gpgme.c
ncrypt/smime.c
nntp/nntp.c
pager.c
pattern.c
recvcmd.c
remailer.c
sendlib.c

index 3d1363be9732bdce31f715aee68add36677291dc..43aba61f1362a2a93e44cbc80851f5247eff9bfb 100644 (file)
@@ -405,8 +405,9 @@ static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t count)
   /* if we still have data in our read buffer, copy it into buf */
   if (sasldata->blen > sasldata->bpos)
   {
-    olen = (sasldata->blen - sasldata->bpos > count) ? count :
-                                                       sasldata->blen - sasldata->bpos;
+    olen = ((sasldata->blen - sasldata->bpos) > count) ?
+               count :
+               sasldata->blen - sasldata->bpos;
 
     memcpy(buf, sasldata->buf + sasldata->bpos, olen);
     sasldata->bpos += olen;
@@ -437,8 +438,9 @@ static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t count)
       }
     } while (sasldata->blen == 0);
 
-    olen = (sasldata->blen - sasldata->bpos > count) ? count :
-                                                       sasldata->blen - sasldata->bpos;
+    olen = ((sasldata->blen - sasldata->bpos) > count) ?
+               count :
+               sasldata->blen - sasldata->bpos;
 
     memcpy(buf, sasldata->buf, olen);
     sasldata->bpos += olen;
diff --git a/copy.c b/copy.c
index bc6ff9a731ae7b36d86f85f3294e4a3647a63d67..89fb7b1ff2de78a22d5fedcf931eeda959be6a34 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -844,7 +844,7 @@ static int append_message(struct Mailbox *dest, FILE *fp_in, struct Mailbox *src
     return -1;
   if ((dest->magic == MUTT_MBOX) || (dest->magic == MUTT_MMDF))
     chflags |= CH_FROM | CH_FORCE_FROM;
-  chflags |= (dest->magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
+  chflags |= ((dest->magic == MUTT_MAILDIR) ? CH_NOSTATUS : CH_UPDATE);
   rc = mutt_copy_message_fp(msg->fp, fp_in, e, cmflags, chflags);
   if (mx_msg_commit(dest, msg) != 0)
     rc = -1;
index 88c531f09050eae91cead5b5284c8818160d1af1..fc045a5fba4756788f1d4d587d6ce06e9976bf32 100644 (file)
@@ -675,7 +675,10 @@ int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname,
     char *pc = mutt_mem_malloc(mutt_str_strlen(prompt) + 3);
 
     sprintf(pc, "%s: ", prompt);
-    mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
+    if (ch.op == OP_NULL)
+      mutt_unget_event(ch.ch, 0);
+    else
+      mutt_unget_event(0, ch.op);
 
     mutt_buffer_increase_size(fname, 1024);
     if (mutt_get_field_full(pc, fname->data, fname->dsize,
diff --git a/edit.c b/edit.c
index 40adea004da87b9a74b90cf3b4cc6aca5ec4216a..e71a5e931df559a04221e08feb852004e7de7863 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -545,7 +545,7 @@ int mutt_builtin_editor(const char *path, struct Email *msg, struct Email *cur)
           }
           break;
         case 'w':
-          be_barf_file(*p ? p : path, buf, buflen);
+          be_barf_file((p[0] != '\0') ? p : path, buf, buflen);
           break;
         case 'x':
           abort = true;
@@ -563,7 +563,7 @@ int mutt_builtin_editor(const char *path, struct Email *msg, struct Email *cur)
       mutt_str_strcat(tmp, sizeof(tmp), "\n");
       if (buflen == bufmax)
         mutt_mem_realloc(&buf, sizeof(char *) * (bufmax += 25));
-      buf[buflen++] = mutt_str_strdup(tmp[1] == '~' ? tmp + 1 : tmp);
+      buf[buflen++] = mutt_str_strdup((tmp[1] == '~') ? tmp + 1 : tmp);
     }
 
     tmp[0] = '\0';
index c8b0e15ee350cae0d537eff5764de7ad643a941f..9b4f0b89a5391b0b7361823179847d6b4c4c3ddc 100644 (file)
@@ -326,7 +326,7 @@ static size_t choose_block(char *d, size_t dlen, int col, const char *fromcode,
     const size_t nn = try_block(d, n, fromcode, tocode, encoder, wlen);
     if ((nn == 0) && (((col + *wlen) <= (ENCWORD_LEN_MAX + 1)) || (n <= 1)))
       break;
-    n = (nn ? nn : n) - 1;
+    n = ((nn != 0) ? nn : n) - 1;
     assert(n > 0);
     if (utf8)
       while ((n > 1) && CONTINUATION_BYTE(d[n]))
index 6ad757f0c9dd114c9a6957c9da81f315ad81b39c..b50a34d818654cf5d2f9307baf521dea73537112 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -330,7 +330,7 @@ static void decode_quoted(struct State *s, long len, bool istext, iconv_t cd)
 
     /* inspect the last character we read so we can tell if we got the
      * entire line.  */
-    const int last = linelen ? line[linelen - 1] : 0;
+    const int last = (linelen != 0) ? line[linelen - 1] : 0;
 
     /* chop trailing whitespace if we got the full line */
     if (last == '\n')
index 6f47d4bce510c59ddc75cbae156acf9449fbe06e..92352b97233bbe40d84a04d0c22db62ac8f3b958 100644 (file)
@@ -241,7 +241,7 @@ void serial_restore_address(struct Address **a, const unsigned char *d, int *off
     serial_restore_char(&(*a)->personal, d, off, convert);
     serial_restore_char(&(*a)->mailbox, d, off, false);
     serial_restore_int(&g, d, off);
-    (*a)->group = g ? true : false;
+    (*a)->group = (g != 0) ? true : false;
     a = &(*a)->next;
     counter--;
   }
diff --git a/menu.c b/menu.c
index e25ed375eb960beef6f66e5d14617fc8db98fa1b..58ad7d3da081b0938ed162dd100ef7b6fc4d6ac5 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1166,7 +1166,8 @@ static int menu_search(struct Menu *menu, int op)
 
   if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
   {
-    mutt_str_strfcpy(buf, search_buf && *search_buf ? search_buf : "", sizeof(buf));
+    mutt_str_strfcpy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "",
+                     sizeof(buf));
     if ((mutt_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
                             _("Search for: ") :
                             _("Reverse search for: "),
@@ -1282,7 +1283,10 @@ static int menu_dialog_dokey(struct Menu *menu, int *ip)
   }
   else
   {
-    mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
+    if (ch.op == OP_NULL)
+      mutt_unget_event(ch.ch, 0);
+    else
+      mutt_unget_event(0, ch.op);
     return -1;
   }
 }
index 58bb73e6e85fc408624478632a0fcfec5a0573b0..c74581568b51fda34f4fc779d39d4d0a56b9da10 100644 (file)
@@ -424,7 +424,7 @@ int log_disp_queue(time_t stamp, const char *file, int line,
   }
 
   struct LogLine *ll = mutt_mem_calloc(1, sizeof(*ll));
-  ll->time = stamp ? stamp : time(NULL);
+  ll->time = (stamp != 0) ? stamp : time(NULL);
   ll->file = file;
   ll->line = line;
   ll->function = function;
index 64d3148883d8c816cb05af6b9710641049b5ba27..273b7b1d196d1623b9682d58f7c4b8b63d9173a4 100644 (file)
@@ -154,7 +154,7 @@ typedef bool (*char_cmp)(char, char);
  */
 static char_cmp get_char_cmp(enum CaseSensitivity cs)
 {
-  return cs == CASE_IGNORE ? char_cmp_lower : char_cmp_identity;
+  return (cs == CASE_IGNORE) ? char_cmp_lower : char_cmp_identity;
 }
 
 /**
index 2210c59e4966bf41eeadcf7dfc67b4b87a041a96..05758e5ad6f3a9d9f8c179c76b4a927c1a2a475c 100644 (file)
@@ -70,7 +70,7 @@ bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *
 
 #ifdef USE_NNTP
   if (a1->type == MUTT_ACCT_TYPE_NNTP)
-    return (a1->flags & MUTT_ACCT_USER) && a1->user[0] ? false : true;
+    return (a1->flags & MUTT_ACCT_USER) && (a1->user[0] != '\0') ? false : true;
 #endif
 
   const char *user = NONULL(Username);
index b5b3f2c556155d1fc835658ba721a4720f3d5c22..246198b26bf05125465d04124d6c3c19534a83d1 100644 (file)
@@ -301,7 +301,7 @@ void mutt_draw_tree(struct Context *ctx)
   {
     if (depth)
     {
-      myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * width;
+      myarrow = arrow + (depth - start_depth - ((start_depth != 0) ? 0 : 1)) * width;
       if (depth && (start_depth == depth))
         myarrow[0] = nextdisp ? MUTT_TREE_LTEE : corner;
       else if (parent->message && !C_HideLimited)
index e32dc6920c7ada696f1a1a22ffbef7c95e5e4a72..852002df2823c311b05c8908dd8f211454702ab9 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1174,7 +1174,7 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c
             /* try to consume as many columns as we can, if we don't have
              * memory for that, use as much memory as possible */
             if (wlen + (pad * pl) + len > buflen)
-              pad = (buflen > wlen + len) ? ((buflen - wlen - len) / pl) : 0;
+              pad = (buflen > (wlen + len)) ? ((buflen - wlen - len) / pl) : 0;
             else
             {
               /* Add pre-spacing to make multi-column pad characters and
index 5f19f77e5ae7cb669e1763fa9faa4d6a5f9daa6f..c5cd0823aac0e78ca1b235359886a17dbfdc8b4d 100644 (file)
@@ -1314,7 +1314,7 @@ static int get_micalg(gpgme_ctx_t ctx, int use_smime, char *buf, size_t buflen)
     }
   }
 
-  return (*buf != '\0') ? 0 : -1;
+  return (buf[0] != '\0') ? 0 : -1;
 }
 
 /**
index 9646a1d5e6ce1a00ef59db92fd0b902fa6c710d8..061c12140ffc17bc1ed6f5f858eea59be67a7362 100644 (file)
@@ -1582,7 +1582,7 @@ struct Body *smime_class_build_smime_entity(struct Body *a, char *certlist)
     {
       off = mutt_str_strlen(certfile);
       snprintf(certfile + off, sizeof(certfile) - off, "%s%s/%s",
-               off ? " " : "", NONULL(C_SmimeCertificates), cert_start);
+               (off != 0) ? " " : "", NONULL(C_SmimeCertificates), cert_start);
     }
     if (cert_end)
       *cert_end++ = ' ';
index 14f9b6dd90d002f45f21ae110c1a25273cb7d00e..16715b521d18f5005da66a7aa458649be7b76475 100644 (file)
@@ -420,7 +420,7 @@ static int nntp_attempt_features(struct NntpAccountData *adata)
 
       while (true)
       {
-        if (buflen - off < 1024)
+        if ((buflen - off) < 1024)
         {
           buflen *= 2;
           mutt_mem_realloc(&adata->overview_fmt, buflen);
diff --git a/pager.c b/pager.c
index 3a1bbda7efd3aee83b7cfe6957852e383f1551e2..bc9496cc43d80c4799c148943616338adebf738e 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1055,8 +1055,9 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n,
       null_rx = false;
       STAILQ_FOREACH(color_line, head, entries)
       {
-        if (!color_line->stop_matching && (regexec(&color_line->regex, buf + offset, 1, pmatch,
-                                                   (offset ? REG_NOTBOL : 0)) == 0))
+        if (!color_line->stop_matching &&
+            (regexec(&color_line->regex, buf + offset, 1, pmatch,
+                     ((offset != 0) ? REG_NOTBOL : 0)) == 0))
         {
           if (pmatch[0].rm_eo != pmatch[0].rm_so)
           {
@@ -1133,7 +1134,7 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n,
       STAILQ_FOREACH(color_line, &ColorAttachList, entries)
       {
         if (regexec(&color_line->regex, buf + offset, 1, pmatch,
-                    (offset ? REG_NOTBOL : 0)) == 0)
+                    ((offset != 0) ? REG_NOTBOL : 0)) == 0)
         {
           if (pmatch[0].rm_eo != pmatch[0].rm_so)
           {
index e0095dc617f09349fd1f8a0e38408367fca68024..e41da2c1c9e4dc00086babb7ea0f57b8fa95d94d 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -1932,7 +1932,7 @@ static bool match_mime_content_type(const struct Pattern *pat,
  */
 static void set_pattern_cache_value(int *cache_entry, int value)
 {
-  *cache_entry = value ? 2 : 1;
+  *cache_entry = (value != 0) ? 2 : 1;
 }
 
 /**
@@ -2533,7 +2533,7 @@ int mutt_search_command(int cur, int op)
   if (!*LastSearch || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
   {
     char buf[256];
-    mutt_str_strfcpy(buf, *LastSearch ? LastSearch : "", sizeof(buf));
+    mutt_str_strfcpy(buf, (LastSearch[0] != '\0') ? LastSearch : "", sizeof(buf));
     if ((mutt_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
                             _("Search for: ") :
                             _("Reverse search for: "),
index 9ef9be5f476d943a7e23ea2611cb9366d0ec6e3e..d2b16fd06796eb6f4a7e72a45e1fc443a42cf170 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -732,7 +732,7 @@ static void attach_forward_msgs(FILE *fp, struct AttachCtx *actx,
 
   struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
   el_add_email(&el, e_cur);
-  ci_send_message(flags, e_tmp, *tmpbody ? tmpbody : NULL, NULL, &el);
+  ci_send_message(flags, e_tmp, (tmpbody[0] != '\0') ? tmpbody : NULL, NULL, &el);
   el_free(&el);
 }
 
index 88125c2f4986f783fb544904bb17ddb8a2c73f79..0f284f8daab957f9db3554a04758ba688c60215c 100644 (file)
@@ -833,7 +833,7 @@ int mix_send_message(struct ListHead *chain, const char *tempfile)
   struct ListNode *np = NULL;
   STAILQ_FOREACH(np, chain, entries)
   {
-    mutt_buffer_addstr(cmd, i ? "," : " -l ");
+    mutt_buffer_addstr(cmd, (i != 0) ? "," : " -l ");
     mutt_buffer_quote_filename(cd_quoted, (char *) np->data, true);
     mutt_buffer_addstr(cmd, mutt_b2s(cd_quoted));
     i = 1;
index 216726cff9c512d82bd74adf32894f4895e97d4a..e203c07365a1735e6e32ad5362c4119e34187354 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -802,7 +802,7 @@ static size_t convert_file_to(FILE *fp, const char *fromcode, int ncodes,
     const char *ib = bufi;
     char *ob = bufu;
     size_t obl = sizeof(bufu);
-    n = iconv(cd1, (ICONV_CONST char **) (ibl ? &ib : 0), &ibl, &ob, &obl);
+    n = iconv(cd1, (ICONV_CONST char **) ((ibl != 0) ? &ib : 0), &ibl, &ob, &obl);
     /* assert(n == (size_t)(-1) || !n); */
     if ((n == (size_t)(-1)) && (((errno != EINVAL) && (errno != E2BIG)) || (ib == bufi)))
     {
@@ -1904,7 +1904,7 @@ static int fold_one_header(FILE *fp, const char *tag, const char *value,
 
   if (tag && *tag && (fprintf(fp, "%s%s: ", NONULL(pfx), tag) < 0))
     return -1;
-  col = mutt_str_strlen(tag) + ((tag && *tag) ? 2 : 0) + mutt_str_strlen(pfx);
+  col = mutt_str_strlen(tag) + ((tag && (tag[0] != '\0')) ? 2 : 0) + mutt_str_strlen(pfx);
 
   while (p && *p)
   {