From 032db326ffd9cf88c838f2a07dc55417c808b20c Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 7 Oct 2017 11:24:25 +0100 Subject: [PATCH] split up 'if' statements that assign and test (2) Split 'if' statements that combine an assignment with a test. e.g. from: if (!(adr = mutt_parse_adrlist(adr, buf))) To: adr = mutt_parse_adrlist(adr, buf); if (!adr) This makes the statements a little easier to read and debug. --- charset.c | 3 ++- commands.c | 3 ++- compose.c | 9 ++++++--- doc/makedoc.c | 41 ++++++++++++++++++++++++++++------------- group.c | 3 ++- imap/browse.c | 9 ++++++--- imap/command.c | 3 ++- imap/imap.c | 33 ++++++++++++++++++++++----------- imap/message.c | 12 ++++++++---- imap/util.c | 6 ++++-- init.c | 6 ++++-- main.c | 3 ++- mbox.c | 7 ++++--- mbyte.c | 3 ++- mh.c | 6 ++++-- mutt_ssl.c | 21 ++++++++++++++------- mutt_ssl_gnutls.c | 9 ++++++--- mx.c | 3 ++- ncrypt/crypt.c | 15 ++++++++++----- ncrypt/crypt_gpgme.c | 39 ++++++++++++++++++++++++++------------- ncrypt/gnupgparse.c | 3 ++- ncrypt/pgp.c | 9 ++++++--- ncrypt/pgppacket.c | 3 ++- ncrypt/smime.c | 9 ++++++--- parse.c | 6 ++++-- pgppubring.c | 3 ++- pop.c | 15 ++++++++++----- query.c | 3 ++- recvcmd.c | 8 +++++--- remailer.c | 21 ++++++++++++++------- rfc2047.c | 3 ++- rfc2231.c | 6 ++++-- send.c | 3 ++- sendlib.c | 18 ++++++++++++------ smtp.c | 6 ++++-- url.c | 3 ++- 36 files changed, 235 insertions(+), 118 deletions(-) diff --git a/charset.c b/charset.c index d75cd1adc..1c25af56c 100644 --- a/charset.c +++ b/charset.c @@ -214,7 +214,8 @@ void mutt_set_langinfo_charset(void) mutt_canonical_charset(buff2, sizeof(buff2), buff); /* finally, set $charset */ - if (!(Charset = safe_strdup(buff2))) + Charset = safe_strdup(buff2); + if (!Charset) Charset = safe_strdup("iso-8859-1"); } diff --git a/commands.c b/commands.c index 932760f12..341eb145f 100644 --- a/commands.c +++ b/commands.c @@ -299,7 +299,8 @@ void ci_bounce_message(struct Header *h) if (rc || !buf[0]) return; - if (!(adr = mutt_parse_adrlist(adr, buf))) + adr = mutt_parse_adrlist(adr, buf); + if (!adr) { mutt_error(_("Error parsing address!")); return; diff --git a/compose.c b/compose.c index 9d1958f2a..12be1ba34 100644 --- a/compose.c +++ b/compose.c @@ -1068,7 +1068,8 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ unset_option(OPT_NEWS); if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) { - if (!(CurrentNewsSrv = nntp_select_server(NewsServer, 0))) + CurrentNewsSrv = nntp_select_server(NewsServer, 0); + if (!CurrentNewsSrv) break; prompt = _("Open newsgroup to attach message from"); @@ -1417,7 +1418,8 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ if (mutt_get_field("Content-Type: ", type, sizeof(type), 0) != 0 || !type[0]) continue; - if (!(p = strchr(type, '/'))) + p = strchr(type, '/'); + if (!p) { mutt_error(_("Content-Type is of the form base/sub")); continue; @@ -1431,7 +1433,8 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ } new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); /* Touch the file */ - if (!(fp = safe_fopen(fname, "w"))) + fp = safe_fopen(fname, "w"); + if (!fp) { mutt_error(_("Can't create file %s"), fname); FREE(&new); diff --git a/doc/makedoc.c b/doc/makedoc.c index d4b6d2343..4804225a7 100644 --- a/doc/makedoc.c +++ b/doc/makedoc.c @@ -1262,21 +1262,25 @@ static void handle_confline(char *s, FILE *out) /* xxx - put this into an actual state machine? */ /* variable name */ - if (!(s = get_token(varname, sizeof(varname), s))) + s = get_token(varname, sizeof(varname), s); + if (!s) return; /* comma */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; /* type */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; type = buff2type(buff); /* possibly a "|" or comma */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; if (strcmp(buff, "|") == 0) @@ -1284,9 +1288,11 @@ static void handle_confline(char *s, FILE *out) if (Debug) fprintf(stderr, "%s: Expecting .\n", Progname); /* ignore subtype and comma */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; } @@ -1294,34 +1300,42 @@ static void handle_confline(char *s, FILE *out) while (true) { - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; if (strcmp(buff, ",") == 0) break; } /* option name or UL &address */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; if (strcmp(buff, "UL") == 0) - if (!(s = get_token(buff, sizeof(buff), s))) + { + s = get_token(buff, sizeof(buff), s); + if (!s) return; + } /* comma */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; if (Debug) fprintf(stderr, "%s: Expecting default value.\n", Progname); /* or UL */ - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; if (strcmp(buff, "UL") == 0) { if (Debug) fprintf(stderr, "%s: Skipping UL.\n", Progname); - if (!(s = get_token(buff, sizeof(buff), s))) + s = get_token(buff, sizeof(buff), s); + if (!s) return; } @@ -1362,7 +1376,8 @@ static void makedoc(FILE *in, FILE *out) else *p = '\0'; - if (!(p = get_token(token, sizeof(token), buffer))) + p = get_token(token, sizeof(token), buffer); + if (!p) continue; if (Debug) diff --git a/group.c b/group.c index e5e7f6f05..462007c6e 100644 --- a/group.c +++ b/group.c @@ -39,7 +39,8 @@ struct Group *mutt_pattern_group(const char *k) if (!k) return 0; - if (!(p = hash_find(Groups, k))) + p = hash_find(Groups, k); + if (!p) { mutt_debug(2, "mutt_pattern_group: Creating group %s.\n", k); p = safe_calloc(1, sizeof(struct Group)); diff --git a/imap/browse.c b/imap/browse.c index 85991bdf9..a80526b33 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -195,7 +195,8 @@ int imap_browse(char *path, struct BrowserState *state) unset_option(OPT_IMAP_CHECK_SUBSCRIBED); strfcpy(list_cmd, option(OPT_IMAP_LIST_SUBSCRIBED) ? "LSUB" : "LIST", sizeof(list_cmd)); - if (!(idata = imap_conn_find(&(mx.account), 0))) + idata = imap_conn_find(&(mx.account), 0); + if (!idata) goto fail; mutt_message(_("Getting folder list...")); @@ -352,7 +353,8 @@ int imap_mailbox_create(const char *folder) return -1; } - if (!(idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW))) + idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + if (!idata) { mutt_debug(1, "imap_mailbox_create: Couldn't find open connection to %s\n", mx.account.host); @@ -406,7 +408,8 @@ int imap_mailbox_rename(const char *mailbox) return -1; } - if (!(idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW))) + idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + if (!idata) { mutt_debug(1, "imap_mailbox_rename: Couldn't find open connection to %s\n", mx.account.host); diff --git a/imap/command.c b/imap/command.c index 2ac821223..4b0cf5767 100644 --- a/imap/command.c +++ b/imap/command.c @@ -127,7 +127,8 @@ static int cmd_queue(struct ImapData *idata, const char *cmdstr, int flags) return rc; } - if (!(cmd = cmd_new(idata))) + cmd = cmd_new(idata); + if (!cmd) return IMAP_CMD_BAD; if (mutt_buffer_printf(idata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0) diff --git a/imap/imap.c b/imap/imap.c index 98fd31c67..b2bad0920 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -88,7 +88,8 @@ int imap_access(const char *path) if (imap_parse_path(path, &mx)) return -1; - if (!(idata = imap_conn_find(&mx.account, option(OPT_IMAP_PASSIVE) ? MUTT_IMAP_CONN_NONEW : 0))) + idata = imap_conn_find(&mx.account, option(OPT_IMAP_PASSIVE) ? MUTT_IMAP_CONN_NONEW : 0); + if (!idata) { FREE(&mx.mbox); return -1; @@ -173,7 +174,8 @@ int imap_delete_mailbox(struct Context *ctx, struct ImapMbox *mx) if (!ctx || !ctx->data) { - if (!(idata = imap_conn_find(&mx->account, option(OPT_IMAP_PASSIVE) ? MUTT_IMAP_CONN_NONEW : 0))) + idata = imap_conn_find(&mx->account, option(OPT_IMAP_PASSIVE) ? MUTT_IMAP_CONN_NONEW : 0); + if (!idata) { FREE(&mx->mbox); return -1; @@ -414,7 +416,8 @@ struct ImapData *imap_conn_find(const struct Account *account, int flags) if (!idata) { /* The current connection is a new connection */ - if (!(idata = imap_new_idata())) + idata = imap_new_idata(); + if (!idata) { mutt_socket_free(conn); return NULL; @@ -627,7 +630,8 @@ static int imap_open_mailbox(struct Context *ctx) } /* we require a connection which isn't currently in IMAP_SELECTED state */ - if (!(idata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NOSELECT))) + idata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NOSELECT); + if (!idata) goto fail_noidata; if (idata->state < IMAP_AUTHENTICATED) goto fail; @@ -840,7 +844,8 @@ static int imap_open_mailbox_append(struct Context *ctx, int flags) /* in APPEND mode, we appear to hijack an existing IMAP connection - * ctx is brand new and mostly empty */ - if (!(idata = imap_conn_find(&(mx.account), 0))) + idata = imap_conn_find(&(mx.account), 0); + if (!idata) { FREE(&mx.mbox); return -1; @@ -1056,7 +1061,8 @@ int imap_exec_msgset(struct ImapData *idata, const char *pre, const char *post, int rc; int count = 0; - if (!(cmd = mutt_buffer_new())) + cmd = mutt_buffer_new(); + if (!cmd) { mutt_debug(1, "imap_exec_msgset: unable to allocate buffer\n"); return -1; @@ -1381,7 +1387,8 @@ static int imap_commit_message_tags(struct Context *ctx, struct Header *h, char /* Remove old custom flags */ if (HEADER_DATA(h)->flags_remote) { - if (!(cmd = mutt_buffer_new())) + cmd = mutt_buffer_new(); + if (!cmd) { mutt_debug(1, "imap_commit_message_tags: unable to allocate buffer\n"); return -1; @@ -1408,7 +1415,8 @@ static int imap_commit_message_tags(struct Context *ctx, struct Header *h, char /* Add new custom flags */ if (tags) { - if (!(cmd = mutt_buffer_new())) + cmd = mutt_buffer_new(); + if (!cmd) { mutt_debug(1, "imap_commit_message_tags: fail to remove old flags\n"); return -1; @@ -2125,7 +2133,8 @@ static int imap_compile_search(struct Context *ctx, const struct Pattern *pat, mutt_buffer_addstr(buf, "HEADER "); /* extract header name */ - if (!(delim = strchr(pat->p.str, ':'))) + delim = strchr(pat->p.str, ':'); + if (!delim) { mutt_error(_("Header search without header name: %s"), pat->p.str); return -1; @@ -2212,7 +2221,8 @@ int imap_subscribe(char *path, int subscribe) mutt_error(_("Bad mailbox name")); return -1; } - if (!(idata = imap_conn_find(&(mx.account), 0))) + idata = imap_conn_find(&(mx.account), 0); + if (!idata) goto fail; imap_fix_path(idata, mx.mbox, buf, sizeof(buf)); @@ -2359,7 +2369,8 @@ int imap_complete(char *dest, size_t dlen, char *path) /* don't open a new socket just for completion. Instead complete over * known mailboxes/hooks/etc */ - if (!(idata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NONEW))) + idata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NONEW); + if (!idata) { FREE(&mx.mbox); strfcpy(dest, path, dlen); diff --git a/imap/message.c b/imap/message.c index 14464f4b4..711ba23cd 100644 --- a/imap/message.c +++ b/imap/message.c @@ -345,7 +345,8 @@ static int msg_fetch_header(struct Context *ctx, struct ImapHeader *h, char *buf return rc; rc = -2; /* we've got a FETCH response, for better or worse */ - if (!(buf = strchr(buf, '('))) + buf = strchr(buf, '('); + if (!buf) return rc; buf++; @@ -534,7 +535,8 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i /* instead of downloading all headers and then parsing them, we parse them * as they come in. */ mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(fp = safe_fopen(tempfile, "w+"))) + fp = safe_fopen(tempfile, "w+"); + if (!fp) { mutt_error(_("Could not create temporary file %s"), tempfile); mutt_sleep(2); @@ -908,12 +910,14 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) if (output_progress) mutt_message(_("Fetching message...")); - if (!(msg->fp = msg_cache_put(idata, h))) + msg->fp = msg_cache_put(idata, h); + if (!msg->fp) { cache->uid = HEADER_DATA(h)->uid; mutt_mktemp(path, sizeof(path)); cache->path = safe_strdup(path); - if (!(msg->fp = safe_fopen(path, "w+"))) + msg->fp = safe_fopen(path, "w+"); + if (!msg->fp) { FREE(&cache->path); return -1; diff --git a/imap/util.c b/imap/util.c index 195071b69..51cd1aad7 100644 --- a/imap/util.c +++ b/imap/util.c @@ -507,11 +507,13 @@ struct ImapData *imap_new_idata(void) { struct ImapData *idata = safe_calloc(1, sizeof(struct ImapData)); - if (!(idata->cmdbuf = mutt_buffer_new())) + idata->cmdbuf = mutt_buffer_new(); + if (!idata->cmdbuf) FREE(&idata); idata->cmdslots = ImapPipelineDepth + 2; - if (!(idata->cmds = safe_calloc(idata->cmdslots, sizeof(*idata->cmds)))) + idata->cmds = safe_calloc(idata->cmdslots, sizeof(*idata->cmds)); + if (!idata->cmds) { mutt_buffer_free(&idata->cmdbuf); FREE(&idata); diff --git a/init.c b/init.c index 4d2eb68ef..780d79304 100644 --- a/init.c +++ b/init.c @@ -781,7 +781,8 @@ int mutt_add_to_regex_list(struct RegexList **list, const char *s, int flags, if (!s || !*s) return 0; - if (!(rx = mutt_compile_regex(s, flags))) + rx = mutt_compile_regex(s, flags); + if (!rx) { snprintf(err->data, err->dsize, "Bad regex: %s\n", s); return -1; @@ -871,7 +872,8 @@ static int add_to_replace_list(struct ReplaceList **list, const char *pat, if (!pat || !*pat || !templ) return 0; - if (!(rx = mutt_compile_regex(pat, REG_ICASE))) + rx = mutt_compile_regex(pat, REG_ICASE); + if (!rx) { snprintf(err->data, err->dsize, _("Bad regex: %s"), pat); return -1; diff --git a/main.c b/main.c index 292fdc0bf..515c0a56c 100644 --- a/main.c +++ b/main.c @@ -869,7 +869,8 @@ int main(int argc, char **argv, char **env) if (flags & MUTT_NEWS) { set_option(OPT_NEWS); - if (!(CurrentNewsSrv = nntp_select_server(NewsServer, 0))) + CurrentNewsSrv = nntp_select_server(NewsServer, 0); + if (!CurrentNewsSrv) { mutt_endwin(ErrorBuf); exit(1); diff --git a/mbox.c b/mbox.c index 78476973d..ca1ae5694 100644 --- a/mbox.c +++ b/mbox.c @@ -611,7 +611,7 @@ static int strict_cmp_envelopes(const struct Envelope *e1, const struct Envelope } else { - if (e1 == NULL && e2 == NULL) + if (!e1 && !e2) return 1; else return 0; @@ -665,7 +665,7 @@ int mbox_strict_cmp_headers(const struct Header *h1, const struct Header *h2) } else { - if (h1 == NULL && h2 == NULL) + if (!h1 && !h2) return 1; else return 0; @@ -743,7 +743,8 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) case MUTT_MMDF: cmp_headers = mbox_strict_cmp_headers; safe_fclose(&ctx->fp); - if (!(ctx->fp = safe_fopen(ctx->path, "r"))) + ctx->fp = safe_fopen(ctx->path, "r"); + if (!ctx->fp) rc = -1; else rc = ((ctx->magic == MUTT_MBOX) ? mbox_parse_mailbox : mmdf_parse_mailbox)(ctx); diff --git a/mbyte.c b/mbyte.c index 4f99cd469..a8fd7752e 100644 --- a/mbyte.c +++ b/mbyte.c @@ -86,7 +86,8 @@ int mutt_filter_unprintable(char **s) char *p = *s; mbstate_t mbstate1, mbstate2; - if (!(b = mutt_buffer_new())) + b = mutt_buffer_new(); + if (!b) return -1; memset(&mbstate1, 0, sizeof(mbstate1)); memset(&mbstate2, 0, sizeof(mbstate2)); diff --git a/mh.c b/mh.c index 245e67679..ee1e7f8ef 100644 --- a/mh.c +++ b/mh.c @@ -178,12 +178,14 @@ static int mh_read_sequences(struct MhSequences *mhs, const char *path) char pathname[_POSIX_PATH_MAX]; snprintf(pathname, sizeof(pathname), "%s/.mh_sequences", path); - if (!(fp = fopen(pathname, "r"))) + fp = fopen(pathname, "r"); + if (!fp) return 0; /* yes, ask callers to silently ignore the error */ while ((buff = mutt_read_line(buff, &sz, fp, &line, 0))) { - if (!(t = strtok(buff, " \t:"))) + t = strtok(buff, " \t:"); + if (!t) continue; if (mutt_strcmp(t, MhSeqUnseen) == 0) diff --git a/mutt_ssl.c b/mutt_ssl.c index 33362c0be..bd7d001bf 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -289,7 +289,8 @@ static void ssl_dprint_err_stack(void) long buflen; char *output = NULL; - if (!(bio = BIO_new(BIO_s_mem()))) + bio = BIO_new(BIO_s_mem()); + if (!bio) return; ERR_print_errors(bio); if ((buflen = BIO_get_mem_data(bio, &buf)) > 0) @@ -718,7 +719,8 @@ static int check_host(X509 *x509cert, const char *hostname, char *err, size_t er if (!match_found) { /* Try the common name */ - if (!(x509_subject = X509_get_subject_name(x509cert))) + x509_subject = X509_get_subject_name(x509cert); + if (!x509_subject) { if (err && errlen) strfcpy(err, _("cannot get certificate subject"), errlen); @@ -960,13 +962,15 @@ static int ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) unsigned int last_cert_mdlen; #endif - if (!(ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()))) + ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); + if (!ssl) { mutt_debug(1, "ssl_verify_callback: failed to retrieve SSL structure from " "X509_STORE_CTX\n"); return 0; } - if (!(host = SSL_get_ex_data(ssl, HostExDataIndex))) + host = SSL_get_ex_data(ssl, HostExDataIndex); + if (!host) { mutt_debug(1, "ssl_verify_callback: failed to retrieve hostname from SSL " "structure\n"); @@ -1151,7 +1155,8 @@ static int ssl_socket_open(struct Connection *conn) data = safe_calloc(1, sizeof(struct SslSockData)); conn->sockdata = data; - if (!(data->ctx = SSL_CTX_new(SSLv23_client_method()))) + data->ctx = SSL_CTX_new(SSLv23_client_method()); + if (!data->ctx) { /* L10N: an SSL context is a data structure returned by the OpenSSL function SSL_CTX_new(). In this case it returned NULL: an @@ -1255,7 +1260,8 @@ int mutt_ssl_starttls(struct Connection *conn) * TLSv1_client_method gives us explicitly TLSv1.0, not 1.1 or 1.2 (True as * of OpenSSL 1.0.1c) */ - if (!(ssldata->ctx = SSL_CTX_new(SSLv23_client_method()))) + ssldata->ctx = SSL_CTX_new(SSLv23_client_method()); + if (!ssldata->ctx) { mutt_debug(1, "mutt_ssl_starttls: Error allocating SSL_CTX\n"); goto bail_ssldata; @@ -1314,7 +1320,8 @@ int mutt_ssl_starttls(struct Connection *conn) mutt_sleep(2); } - if (!(ssldata->ssl = SSL_new(ssldata->ctx))) + ssldata->ssl = SSL_new(ssldata->ctx); + if (!ssldata->ssl) { mutt_debug(1, "mutt_ssl_starttls: Error allocating SSL\n"); goto bail_ctx; diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index d4d44aae0..347bf5687 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -874,7 +874,8 @@ static void tls_get_client_cert(struct Connection *conn) size_t dnlen; /* get our cert CN if we have one */ - if (!(crtdata = gnutls_certificate_get_ours(data->state))) + crtdata = gnutls_certificate_get_ours(data->state); + if (!crtdata) return; if (gnutls_x509_crt_init(&clientcrt) < 0) @@ -890,7 +891,8 @@ static void tls_get_client_cert(struct Connection *conn) /* get length of DN */ dnlen = 0; gnutls_x509_crt_get_dn(clientcrt, NULL, &dnlen); - if (!(dn = calloc(1, dnlen))) + dn = calloc(1, dnlen); + if (!dn) { mutt_debug(1, "could not allocate DN\n"); goto err_crt; @@ -899,7 +901,8 @@ static void tls_get_client_cert(struct Connection *conn) mutt_debug(2, "client certificate DN: %s\n", dn); /* extract CN to use as external user name */ - if (!(cn = strstr(dn, "CN="))) + cn = strstr(dn, "CN="); + if (!cn) { mutt_debug(1, "no CN found in DN\n"); goto err_dn; diff --git a/mx.c b/mx.c index 3406a0712..158102450 100644 --- a/mx.c +++ b/mx.c @@ -424,7 +424,8 @@ struct Context *mx_open_mailbox(const char *path, int flags, struct Context *pct FREE(&ctx); return NULL; } - if (!(ctx->realpath = realpath(ctx->path, NULL))) + ctx->realpath = realpath(ctx->path, NULL); + if (!ctx->realpath) ctx->realpath = safe_strdup(ctx->path); ctx->msgnotreadyet = -1; diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index e3fd0356e..9ac94c4d0 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -231,7 +231,8 @@ int mutt_protect(struct Header *msg, char *keylist) { if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME)) { - if (!(tmp_pbody = crypt_smime_sign_message(msg->content))) + tmp_pbody = crypt_smime_sign_message(msg->content); + if (!tmp_pbody) return -1; pbody = tmp_smime_pbody = tmp_pbody; } @@ -239,7 +240,8 @@ int mutt_protect(struct Header *msg, char *keylist) if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP) && (!(flags & ENCRYPT) || option(OPT_PGP_RETAINABLE_SIGS))) { - if (!(tmp_pbody = crypt_pgp_sign_message(msg->content))) + tmp_pbody = crypt_pgp_sign_message(msg->content); + if (!tmp_pbody) return -1; flags &= ~SIGN; @@ -317,7 +319,8 @@ int mutt_is_multipart_signed(struct Body *b) (mutt_strcasecmp(b->subtype, "signed") != 0)) return 0; - if (!(p = mutt_get_parameter("protocol", b->parameter))) + p = mutt_get_parameter("protocol", b->parameter); + if (!p) return 0; if (!(mutt_strcasecmp(p, "multipart/mixed") != 0)) @@ -614,7 +617,8 @@ int crypt_write_signed(struct Body *a, struct State *s, const char *tempfile) if (!WithCrypto) return -1; - if (!(fp = safe_fopen(tempfile, "w"))) + fp = safe_fopen(tempfile, "w"); + if (!fp) { mutt_perror(tempfile); return -1; @@ -692,7 +696,8 @@ void crypt_extract_keys_from_messages(struct Header *h) return; mutt_mktemp(tempfname, sizeof(tempfname)); - if (!(fpout = safe_fopen(tempfname, "w"))) + fpout = safe_fopen(tempfname, "w"); + if (!fpout) { mutt_perror(tempfname); return; diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 3f2292160..4511065e8 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -1984,7 +1984,8 @@ int pgp_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body } mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(*fpout = safe_fopen(tempfile, "w+"))) + *fpout = safe_fopen(tempfile, "w+"); + if (!*fpout) { mutt_perror(tempfile); rv = -1; @@ -2045,7 +2046,8 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = fpin; fseeko(s.fpin, b->offset, SEEK_SET); mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(tmpfp = safe_fopen(tempfile, "w+"))) + tmpfp = safe_fopen(tempfile, "w+"); + if (!tmpfp) { mutt_perror(tempfile); return -1; @@ -2063,7 +2065,8 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = tmpfp; s.fpout = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(*fpout = safe_fopen(tempfile, "w+"))) + *fpout = safe_fopen(tempfile, "w+"); + if (!*fpout) { mutt_perror(tempfile); return -1; @@ -2099,7 +2102,8 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = *fpout; fseeko(s.fpin, bb->offset, SEEK_SET); mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(tmpfp = safe_fopen(tempfile, "w+"))) + tmpfp = safe_fopen(tempfile, "w+"); + if (!tmpfp) { mutt_perror(tempfile); return -1; @@ -2118,7 +2122,8 @@ int smime_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Bo s.fpin = tmpfp; s.fpout = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(*fpout = safe_fopen(tempfile, "w+"))) + *fpout = safe_fopen(tempfile, "w+"); + if (!*fpout) { mutt_perror(tempfile); return -1; @@ -2373,7 +2378,8 @@ void pgp_gpgme_invoke_import(const char *fname) FILE *in = NULL; FILE *out = NULL; - if (!(in = safe_fopen(fname, "r"))) + in = safe_fopen(fname, "r"); + if (!in) return; /* Note that the stream, "in", needs to be kept open while the keydata * is used. @@ -2731,7 +2737,8 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) mutt_debug(2, "Entering pgp_encrypted handler\n"); mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(fpout = safe_fopen(tempfile, "w+"))) + fpout = safe_fopen(tempfile, "w+"); + if (!fpout) { if (s->flags & MUTT_DISPLAY) state_attach_puts(_("[-- Error: could not create temporary file! " @@ -2808,7 +2815,8 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) a->warnsig = false; mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(fpout = safe_fopen(tempfile, "w+"))) + fpout = safe_fopen(tempfile, "w+"); + if (!fpout) { if (s->flags & MUTT_DISPLAY) state_attach_puts(_("[-- Error: could not create temporary file! " @@ -2842,7 +2850,8 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) */ if (mutt_is_multipart_signed(tattach) && !tattach->next) { - if (!(a->goodsig = tattach->goodsig)) + a->goodsig = tattach->goodsig; + if (!a->goodsig) a->warnsig = tattach->warnsig; } else if (tattach->goodsig) @@ -3488,19 +3497,22 @@ static unsigned int key_check_cap(gpgme_key_t key, enum KeyCap cap) switch (cap) { case KEY_CAP_CAN_ENCRYPT: - if (!(ret = key->can_encrypt)) + ret = key->can_encrypt; + if (ret == 0) for (subkey = key->subkeys; subkey; subkey = subkey->next) if ((ret = subkey->can_encrypt)) break; break; case KEY_CAP_CAN_SIGN: - if (!(ret = key->can_sign)) + ret = key->can_sign; + if (ret == 0) for (subkey = key->subkeys; subkey; subkey = subkey->next) if ((ret = subkey->can_sign)) break; break; case KEY_CAP_CAN_CERTIFY: - if (!(ret = key->can_certify)) + ret = key->can_certify; + if (ret == 0) for (subkey = key->subkeys; subkey; subkey = subkey->next) if ((ret = subkey->can_certify)) break; @@ -3809,7 +3821,8 @@ static void verify_key(struct CryptKeyInfo *key) int maxdepth = 100; mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(fp = safe_fopen(tempfile, "w"))) + fp = safe_fopen(tempfile, "w"); + if (!fp) { mutt_perror(_("Can't create temporary file")); return; diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index 62a41dcb4..a781c3f6e 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -407,7 +407,8 @@ struct PgpKeyInfo *pgp_get_candidates(enum PgpRing keyring, struct ListHead *hin k = NULL; while (fgets(buf, sizeof(buf) - 1, fp)) { - if (!(kk = parse_pub_line(buf, &is_sub, k))) + kk = parse_pub_line(buf, &is_sub, k); + if (!kk) continue; /* Only append kk to the list if it's new. */ diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 19f7d150b..4900d5287 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -713,7 +713,8 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) snprintf(sigfile, sizeof(sigfile), "%s.asc", tempfile); - if (!(fp = safe_fopen(sigfile, "w"))) + fp = safe_fopen(sigfile, "w"); + if (!fp) { mutt_perror(sigfile); return -1; @@ -724,7 +725,8 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) safe_fclose(&fp); mutt_mktemp(pgperrfile, sizeof(pgperrfile)); - if (!(pgperr = safe_fopen(pgperrfile, "w+"))) + pgperr = safe_fopen(pgperrfile, "w+"); + if (!pgperr) { mutt_perror(pgperrfile); unlink(sigfile); @@ -774,7 +776,8 @@ static void pgp_extract_keys_from_attachment(FILE *fp, struct Body *top) char tempfname[_POSIX_PATH_MAX]; mutt_mktemp(tempfname, sizeof(tempfname)); - if (!(tempfp = safe_fopen(tempfname, "w"))) + tempfp = safe_fopen(tempfname, "w"); + if (!tempfp) { mutt_perror(tempfname); return; diff --git a/ncrypt/pgppacket.c b/ncrypt/pgppacket.c index 14a11187f..c741d7506 100644 --- a/ncrypt/pgppacket.c +++ b/ncrypt/pgppacket.c @@ -40,7 +40,8 @@ static int read_material(size_t material, size_t *used, FILE *fp) nplen = *used + material + CHUNKSIZE; - if (!(p = realloc(pbuf, nplen))) + p = realloc(pbuf, nplen); + if (!p) { perror("realloc"); return -1; diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 6c4ddd18c..20479a29a 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -1245,7 +1245,8 @@ int smime_verify_sender(struct Header *h) int retval = 1; mutt_mktemp(tempfname, sizeof(tempfname)); - if (!(fpout = safe_fopen(tempfname, "w"))) + fpout = safe_fopen(tempfname, "w"); + if (!fpout) { mutt_perror(tempfname); return 1; @@ -1677,7 +1678,8 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) sigbdy->type = origType; mutt_mktemp(smimeerrfile, sizeof(smimeerrfile)); - if (!(smimeerr = safe_fopen(smimeerrfile, "w+"))) + smimeerr = safe_fopen(smimeerrfile, "w+"); + if (!smimeerr) { mutt_perror(smimeerrfile); mutt_unlink(signedfile); @@ -1989,7 +1991,8 @@ int smime_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body **c } mutt_unlink(tempfile); - if (!(*cur = smime_handle_entity(b, &s, *fpout))) + *cur = smime_handle_entity(b, &s, *fpout); + if (!*cur) { rv = -1; goto bail; diff --git a/parse.c b/parse.c index 080c676c2..c87ad5f1a 100644 --- a/parse.c +++ b/parse.c @@ -381,7 +381,8 @@ void mutt_parse_content_type(char *s, struct Body *ct) /* Default character set for text types. */ if (ct->type == TYPETEXT) { - if (!(pc = mutt_get_parameter("charset", ct->parameter))) + pc = mutt_get_parameter("charset", ct->parameter); + if (!pc) mutt_set_parameter("charset", (AssumedCharset && *AssumedCharset) ? (const char *) mutt_get_default_charset() : @@ -909,7 +910,8 @@ int mutt_parse_rfc822_line(struct Envelope *e, struct Header *hdr, char *line, for (beg = strchr(p, '<'); beg; beg = strchr(end, ',')) { beg++; - if (!(end = strchr(beg, '>'))) + end = strchr(beg, '>'); + if (!end) break; /* Take the first mailto URL */ diff --git a/pgppubring.c b/pgppubring.c index d087e7bfa..dce20b96e 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -652,7 +652,8 @@ static struct PgpKeyInfo *pgp_parse_keyblock(FILE *fp) case PT_SUBKEY: case PT_SUBSECKEY: { - if (!(*last = p = pgp_parse_keyinfo(buff, l))) + *last = p = pgp_parse_keyinfo(buff, l); + if (!*last) { err = 1; break; diff --git a/pop.c b/pop.c index 0ab5349c4..a9912ea7a 100644 --- a/pop.c +++ b/pop.c @@ -87,7 +87,8 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h) char tempfile[_POSIX_PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); - if (!(f = safe_fopen(tempfile, "w+"))) + f = safe_fopen(tempfile, "w+"); + if (!f) { mutt_perror(tempfile); return -3; @@ -201,9 +202,11 @@ static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data) struct Context *ctx = NULL; struct PopData *pop_data = NULL; - if (!(ctx = (struct Context *) data)) + ctx = (struct Context *) data; + if (!ctx) return -1; - if (!(pop_data = (struct PopData *) ctx->data)) + pop_data = (struct PopData *) ctx->data; + if (!pop_data) return -1; #ifdef USE_HCACHE @@ -599,12 +602,14 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno NetInc, h->content->length + h->content->offset - 1); /* see if we can put in body cache; use our cache as fallback */ - if (!(msg->fp = mutt_bcache_put(pop_data->bcache, h->data))) + msg->fp = mutt_bcache_put(pop_data->bcache, h->data); + if (!msg->fp) { /* no */ bcache = 0; mutt_mktemp(path, sizeof(path)); - if (!(msg->fp = safe_fopen(path, "w+"))) + msg->fp = safe_fopen(path, "w+"); + if (!msg->fp) { mutt_perror(path); mutt_sleep(2); diff --git a/query.c b/query.c index 82e482c47..ba5cc0f8b 100644 --- a/query.c +++ b/query.c @@ -82,7 +82,8 @@ static struct Address *result_to_addr(struct Query *r) { static struct Address *tmp = NULL; - if (!(tmp = rfc822_cpy_adr(r->addr, 0))) + tmp = rfc822_cpy_adr(r->addr, 0); + if (!tmp) return NULL; if (!tmp->next && !tmp->personal) diff --git a/recvcmd.c b/recvcmd.c index e12a284c7..95c23ca2b 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -171,7 +171,8 @@ void mutt_attach_bounce(FILE *fp, struct Header *hdr, struct AttachCtx *actx, st if (mutt_get_field(prompt, buf, sizeof(buf), MUTT_ALIAS) || buf[0] == '\0') return; - if (!(adr = rfc822_parse_adrlist(adr, buf))) + adr = rfc822_parse_adrlist(adr, buf); + if (!adr) { mutt_error(_("Error parsing address!")); return; @@ -589,7 +590,8 @@ static void attach_forward_msgs(FILE *fp, struct Header *hdr, /* no MIME encapsulation */ mutt_mktemp(tmpbody, sizeof(tmpbody)); - if (!(tmpfp = safe_fopen(tmpbody, "w"))) + tmpfp = safe_fopen(tmpbody, "w"); + if (!tmpfp) { mutt_error(_("Can't create %s."), tmpbody); mutt_free_header(&tmphdr); @@ -709,7 +711,7 @@ static int attach_reply_envelope_defaults(struct Envelope *env, struct AttachCtx curhdr = parent; } - if (curenv == NULL || curhdr == NULL) + if (!curenv || !curhdr) { mutt_error(_("Can't find any tagged messages.")); return -1; diff --git a/remailer.c b/remailer.c index d7e25e79b..e55420237 100644 --- a/remailer.c +++ b/remailer.c @@ -165,25 +165,30 @@ static struct Remailer **mix_type2_list(size_t *l) { p = mix_new_remailer(); - if (!(t = strtok(line, " \t\n"))) + t = strtok(line, " \t\n"); + if (!t) goto problem; p->shortname = safe_strdup(t); - if (!(t = strtok(NULL, " \t\n"))) + t = strtok(NULL, " \t\n"); + if (!t) goto problem; p->addr = safe_strdup(t); - if (!(t = strtok(NULL, " \t\n"))) + t = strtok(NULL, " \t\n"); + if (!t) goto problem; - if (!(t = strtok(NULL, " \t\n"))) + t = strtok(NULL, " \t\n"); + if (!t) goto problem; p->ver = safe_strdup(t); - if (!(t = strtok(NULL, " \t\n"))) + t = strtok(NULL, " \t\n"); + if (!t) goto problem; p->caps = mix_get_caps(t); @@ -470,7 +475,8 @@ void mix_make_chain(struct ListHead *chainhead) int j; char *t = NULL; - if (!(type2_list = mix_type2_list(&ttll))) + type2_list = mix_type2_list(&ttll); + if (!type2_list) { mutt_error(_("Can't get mixmaster's type2.list!")); return; @@ -692,7 +698,8 @@ int mix_check_message(struct Header *msg) if (need_hostname) { - if (!(fqdn = mutt_fqdn(1))) + fqdn = mutt_fqdn(1); + if (!fqdn) { mutt_error(_("Please set the hostname variable to a proper value when " "using mixmaster!")); diff --git a/rfc2047.c b/rfc2047.c index 64e8dfadc..b73e93d6a 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -802,7 +802,8 @@ void rfc2047_decode(char **pd) while (*s && dlen > 0) { - if (!(p = find_encoded_word(s, &q))) + p = find_encoded_word(s, &q); + if (!p) { /* no encoded words */ if (option(OPT_IGNORE_LINEAR_WHITE_SPACE)) diff --git a/rfc2231.c b/rfc2231.c index 2092bd228..b7a080887 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -79,7 +79,8 @@ static char *rfc2231_get_charset(char *value, char *charset, size_t chslen) { char *t = NULL, *u = NULL; - if (!(t = strchr(value, '\''))) + t = strchr(value, '\''); + if (!t) { charset[0] = '\0'; return value; @@ -232,7 +233,8 @@ void rfc2231_decode_parameters(struct Parameter **headp) { q = p->next; - if (!(s = strchr(p->attribute, '*'))) + s = strchr(p->attribute, '*'); + if (!s) { /* * Using RFC2047 encoding in MIME parameters is explicitly diff --git a/send.c b/send.c index 1ace79803..ba69bef50 100644 --- a/send.c +++ b/send.c @@ -1425,7 +1425,8 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, pbody->next = msg->content; /* don't kill command-line attachments */ msg->content = pbody; - if (!(ctype = safe_strdup(ContentType))) + ctype = safe_strdup(ContentType); + if (!ctype) ctype = safe_strdup("text/plain"); mutt_parse_content_type(ctype, msg->content); FREE(&ctype); diff --git a/sendlib.c b/sendlib.c index 2ff4b2443..ccf92fc9b 100644 --- a/sendlib.c +++ b/sendlib.c @@ -384,7 +384,8 @@ int mutt_write_mime_header(struct Body *a, FILE *f) if (a->use_disp) { - if (!(fn = a->d_filename)) + fn = a->d_filename; + if (!fn) fn = a->filename; if (fn) @@ -436,7 +437,8 @@ int mutt_write_mime_body(struct Body *a, FILE *f) if (a->type == TYPEMULTIPART) { /* First, find the boundary to use */ - if (!(p = mutt_get_parameter("boundary", a->parameter))) + p = mutt_get_parameter("boundary", a->parameter); + if (!p) { mutt_debug(1, "mutt_write_mime_body(): no boundary parameter found!\n"); mutt_error(_("No boundary parameter found! [report this error]")); @@ -1194,7 +1196,8 @@ void mutt_message_to_7bit(struct Body *a, FILE *fp) } mutt_mktemp(temp, sizeof(temp)); - if (!(fpout = safe_fopen(temp, "w+"))) + fpout = safe_fopen(temp, "w+"); + if (!fpout) { mutt_perror("fopen"); goto cleanup; @@ -1900,7 +1903,8 @@ static int write_one_header(FILE *fp, int pfxw, int max, int wraplen, const char } } - if (!(t = strchr(valbuf, ':'))) + t = strchr(valbuf, ':'); + if (!t) { mutt_debug(1, "mwoh: warning: header not in 'key: value' format!\n"); FREE(&valbuf); @@ -2230,7 +2234,8 @@ static void encode_headers(struct ListHead *h) struct ListNode *np; STAILQ_FOREACH(np, h, entries) { - if (!(p = strchr(np->data, ':'))) + p = strchr(np->data, ':'); + if (!p) continue; i = p - np->data; @@ -2286,7 +2291,8 @@ static char *gen_msgid(void) rndid[MUTT_RANDTAG_LEN] = 0; now = time(NULL); tm = gmtime(&now); - if (!(fqdn = mutt_fqdn(0))) + fqdn = mutt_fqdn(0); + if (!fqdn) fqdn = NONULL(ShortHostname); snprintf(buf, sizeof(buf), "<%d%02d%02d%02d%02d%02d.%s@%s>", tm->tm_year + 1900, diff --git a/smtp.c b/smtp.c index 2df073377..e1f7a0b34 100644 --- a/smtp.c +++ b/smtp.c @@ -345,7 +345,8 @@ static int smtp_helo(struct Connection *conn) #endif } - if (!(fqdn = mutt_fqdn(0))) + fqdn = mutt_fqdn(0); + if (!fqdn) fqdn = NONULL(ShortHostname); snprintf(buf, sizeof(buf), "%s %s\r\n", Esmtp ? "EHLO" : "HELO", fqdn); @@ -659,7 +660,8 @@ int mutt_smtp_send(const struct Address *from, const struct Address *to, if (smtp_fill_account(&account) < 0) return ret; - if (!(conn = mutt_conn_find(NULL, &account))) + conn = mutt_conn_find(NULL, &account); + if (!conn) return -1; Esmtp = eightbit; diff --git a/url.c b/url.c index 95c87531a..34972100a 100644 --- a/url.c +++ b/url.c @@ -271,7 +271,8 @@ int url_parse_mailto(struct Envelope *e, char **body, const char *src) int rc = -1; - if (!(t = strchr(src, ':'))) + t = strchr(src, ':'); + if (!t) return -1; /* copy string for safe use of strtok() */ -- 2.40.0