From e32852ab2640f11b996d28234d8ffaef9cc2ead1 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 15 May 2019 23:53:37 +0100 Subject: [PATCH] tidy ternary operators - insert ()s - expand checks against 0 or '\0' --- conn/sasl.c | 10 ++++++---- copy.c | 2 +- curs_lib.c | 5 ++++- edit.c | 4 ++-- email/rfc2047.c | 2 +- handler.c | 2 +- hcache/serialize.c | 2 +- menu.c | 8 ++++++-- mutt/logging.c | 2 +- mutt/string.c | 2 +- mutt_account.c | 2 +- mutt_thread.c | 2 +- muttlib.c | 2 +- ncrypt/crypt_gpgme.c | 2 +- ncrypt/smime.c | 2 +- nntp/nntp.c | 2 +- pager.c | 7 ++++--- pattern.c | 4 ++-- recvcmd.c | 2 +- remailer.c | 2 +- sendlib.c | 4 ++-- 21 files changed, 40 insertions(+), 30 deletions(-) diff --git a/conn/sasl.c b/conn/sasl.c index 3d1363be9..43aba61f1 100644 --- a/conn/sasl.c +++ b/conn/sasl.c @@ -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 bc6ff9a73..89fb7b1ff 100644 --- 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; diff --git a/curs_lib.c b/curs_lib.c index 88c531f09..fc045a5fb 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -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 40adea004..e71a5e931 100644 --- 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'; diff --git a/email/rfc2047.c b/email/rfc2047.c index c8b0e15ee..9b4f0b89a 100644 --- a/email/rfc2047.c +++ b/email/rfc2047.c @@ -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])) diff --git a/handler.c b/handler.c index 6ad757f0c..b50a34d81 100644 --- 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') diff --git a/hcache/serialize.c b/hcache/serialize.c index 6f47d4bce..92352b972 100644 --- a/hcache/serialize.c +++ b/hcache/serialize.c @@ -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 e25ed375e..58ad7d3da 100644 --- 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; } } diff --git a/mutt/logging.c b/mutt/logging.c index 58bb73e6e..c74581568 100644 --- a/mutt/logging.c +++ b/mutt/logging.c @@ -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; diff --git a/mutt/string.c b/mutt/string.c index 64d314888..273b7b1d1 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -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; } /** diff --git a/mutt_account.c b/mutt_account.c index 2210c59e4..05758e5ad 100644 --- a/mutt_account.c +++ b/mutt_account.c @@ -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); diff --git a/mutt_thread.c b/mutt_thread.c index b5b3f2c55..246198b26 100644 --- a/mutt_thread.c +++ b/mutt_thread.c @@ -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) diff --git a/muttlib.c b/muttlib.c index e32dc6920..852002df2 100644 --- 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 diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 5f19f77e5..c5cd0823a 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -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; } /** diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 9646a1d5e..061c12140 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -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++ = ' '; diff --git a/nntp/nntp.c b/nntp/nntp.c index 14f9b6dd9..16715b521 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -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 3a1bbda7e..bc9496cc4 100644 --- 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) { diff --git a/pattern.c b/pattern.c index e0095dc61..e41da2c1c 100644 --- 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: "), diff --git a/recvcmd.c b/recvcmd.c index 9ef9be5f4..d2b16fd06 100644 --- 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); } diff --git a/remailer.c b/remailer.c index 88125c2f4..0f284f8da 100644 --- a/remailer.c +++ b/remailer.c @@ -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; diff --git a/sendlib.c b/sendlib.c index 216726cff..e203c0736 100644 --- 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) { -- 2.40.0