From d83f7793ff9d25d6a042f004ad638825ec9163a0 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 7 Oct 2017 21:37:34 +0100 Subject: [PATCH] simplify null checks Simplify checks: * `if (x == NULL)` -> `if (!x)` * `if (x != NULL)` -> `if (x)` --- browser.c | 2 +- compose.c | 4 ++-- copy.c | 2 +- headers.c | 4 ++-- lib/file.c | 2 +- lib/memory.c | 4 ++-- main.c | 2 +- mbox.c | 4 ++-- mutt_lua.c | 4 ++-- pager.c | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/browser.c b/browser.c index 5f8174af1..f70c8ef82 100644 --- a/browser.c +++ b/browser.c @@ -577,7 +577,7 @@ static const char *newsgroup_format_str(char *dest, size_t destlen, size_t col, break; case 'd': - if (folder->ff->nd->desc != NULL) + if (folder->ff->nd->desc) { char *buf = safe_strdup(folder->ff->nd->desc); if (NewsgroupsCharset && *NewsgroupsCharset) diff --git a/compose.c b/compose.c index 9bfb4c63a..0e211c747 100644 --- a/compose.c +++ b/compose.c @@ -1033,7 +1033,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); new->unowned = 1; new->content = mutt_make_file_attach(att); - if (new->content != NULL) + if (new->content) update_idx(menu, actx, new); else { @@ -1155,7 +1155,7 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ { new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); new->content = mutt_make_message_attach(Context, h, 1); - if (new->content != NULL) + if (new->content) update_idx(menu, actx, new); else { diff --git a/copy.c b/copy.c index 931af0878..6242a85ee 100644 --- a/copy.c +++ b/copy.c @@ -470,7 +470,7 @@ int mutt_copy_header(FILE *in, struct Header *h, FILE *out, int flags, const cha if (flags & CH_UPDATE_LABEL) { h->xlabel_changed = false; - if (h->env->x_label != NULL) + if (h->env->x_label) if (fprintf(out, "X-Label: %s\n", h->env->x_label) != 10 + strlen(h->env->x_label)) return -1; } diff --git a/headers.c b/headers.c index ab43b3824..9c8b620ef 100644 --- a/headers.c +++ b/headers.c @@ -268,10 +268,10 @@ static int label_message(struct Context *ctx, struct Header *hdr, char *new) if (mutt_strcmp(hdr->env->x_label, new) == 0) return 0; - if (hdr->env->x_label != NULL) + if (hdr->env->x_label) label_ref_dec(ctx, hdr->env->x_label); mutt_str_replace(&hdr->env->x_label, new); - if (hdr->env->x_label != NULL) + if (hdr->env->x_label) label_ref_inc(ctx, hdr->env->x_label); return hdr->changed = hdr->xlabel_changed = true; diff --git a/lib/file.c b/lib/file.c index f8ae14f73..971fddcef 100644 --- a/lib/file.c +++ b/lib/file.c @@ -127,7 +127,7 @@ static int mkwrapdir(const char *path, char *newfile, size_t nflen, char *newdir } snprintf(newdir, ndlen, "%s/%s", parent, ".muttXXXXXX"); - if (mkdtemp(newdir) == NULL) + if (!mkdtemp(newdir)) { mutt_debug(1, "mkwrapdir: mkdtemp() failed\n"); return -1; diff --git a/lib/memory.c b/lib/memory.c index 25fb467a2..89e7a6249 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -109,9 +109,9 @@ void *safe_malloc(size_t size) void *p = NULL; if (size == 0) - return 0; + return NULL; p = malloc(size); - if (p == NULL) + if (!p) { mutt_error(_("Out of memory!")); sleep(1); diff --git a/main.c b/main.c index dac5d4083..11f501d28 100644 --- a/main.c +++ b/main.c @@ -150,7 +150,7 @@ static void start_curses(void) its own SIGWINCH handler */ mutt_signal_init(); #endif - if (initscr() == NULL) + if (!initscr()) { puts(_("Error initializing terminal.")); exit(1); diff --git a/mbox.c b/mbox.c index b583be3a7..1d55224fd 100644 --- a/mbox.c +++ b/mbox.c @@ -784,7 +784,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) */ for (j = i; j < old_msgcount; j++) { - if (old_hdrs[j] == NULL) + if (!old_hdrs[j]) continue; if (cmp_headers(ctx->hdrs[i], old_hdrs[j])) { @@ -796,7 +796,7 @@ static int reopen_mailbox(struct Context *ctx, int *index_hint) { for (j = 0; j < i && j < old_msgcount; j++) { - if (old_hdrs[j] == NULL) + if (!old_hdrs[j]) continue; if (cmp_headers(ctx->hdrs[i], old_hdrs[j])) { diff --git a/mutt_lua.c b/mutt_lua.c index a7f95e60c..c6f7d805b 100644 --- a/mutt_lua.c +++ b/mutt_lua.c @@ -358,12 +358,12 @@ static void luaopen_mutt(lua_State *l) static bool _lua_init(lua_State **l) { - if (*l == NULL) + if (!*l) { mutt_debug(2, " * lua_init()\n"); *l = luaL_newstate(); - if (*l == NULL) + if (!*l) { mutt_error("Error: Couldn't load the lua interpreter."); return false; diff --git a/pager.c b/pager.c index d0878b796..ee61b2f2f 100644 --- a/pager.c +++ b/pager.c @@ -445,7 +445,7 @@ static struct QClass *classify_quote(struct QClass **quote_list, const char *qpt { /* not much point in classifying quotes... */ - if (*quote_list == NULL) + if (!*quote_list) { class = safe_calloc(1, sizeof(struct QClass)); class->color = ColorQuote[0]; -- 2.40.0