From fe42292cdd98a61180e564cc7f113e8354ac04a9 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 25 May 2019 16:08:51 +0100 Subject: [PATCH] coverity --- address/address.c | 4 +++- alias.c | 2 +- browser.c | 2 +- hook.c | 2 +- keymap.c | 3 ++- maildir/shared.c | 3 +++ mutt/envlist.c | 2 +- mutt/regex.c | 2 +- muttlib.c | 16 ++++++++++------ pattern.c | 4 ++-- pattern.h | 2 +- 11 files changed, 26 insertions(+), 16 deletions(-) diff --git a/address/address.c b/address/address.c index 190299626..ce282c407 100644 --- a/address/address.c +++ b/address/address.c @@ -1297,7 +1297,9 @@ void mutt_addrlist_dedupe(struct AddressList *al) { if (a->mailbox) { - struct Address *a2 = TAILQ_NEXT(a, entries), *tmp; + struct Address *a2 = TAILQ_NEXT(a, entries); + struct Address *tmp = NULL; + if (a2) { TAILQ_FOREACH_FROM_SAFE(a2, al, entries, tmp) diff --git a/alias.c b/alias.c index e469c04e4..5ae0ce069 100644 --- a/alias.c +++ b/alias.c @@ -326,7 +326,7 @@ struct AddressList *mutt_get_address(struct Envelope *env, const char **pfxp) if (mutt_addr_is_user(TAILQ_FIRST(&env->from))) { - if (TAILQ_EMPTY(&env->to) && !mutt_is_mail_list(TAILQ_FIRST(&env->to))) + if (!TAILQ_EMPTY(&env->to) && !mutt_is_mail_list(TAILQ_FIRST(&env->to))) { pfx = "To"; al = &env->to; diff --git a/browser.c b/browser.c index 7b06ff361..1ac20d556 100644 --- a/browser.c +++ b/browser.c @@ -788,7 +788,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state, break; } - if (np && Context && + if (np && Context && Context->mailbox && (mutt_str_strcmp(np->mailbox->realpath, Context->mailbox->realpath) == 0)) { np->mailbox->msg_count = Context->mailbox->msg_count; diff --git a/hook.c b/hook.c index 71a7f5a6f..0223e549a 100644 --- a/hook.c +++ b/hook.c @@ -428,7 +428,7 @@ int mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, * used for date ranges, and they need to be evaluated relative to "now", not * the hook compilation time. */ struct PatternHead *pat = - mutt_pattern_comp(pattern->data, MUTT_FULL_MSG | MUTT_PATTERN_DYNAMIC, err); + mutt_pattern_comp(mutt_b2s(pattern), MUTT_FULL_MSG | MUTT_PATTERN_DYNAMIC, err); if (!pat) goto out; diff --git a/keymap.c b/keymap.c index d2f557c63..6a4543caa 100644 --- a/keymap.c +++ b/keymap.c @@ -1358,7 +1358,8 @@ static void km_unbind_all(struct Keymap **map, unsigned long mode) } else if (!first) { - first = last = cur; + first = cur; + last = cur; } else if (last) { diff --git a/maildir/shared.c b/maildir/shared.c index 7e17f7f5b..6feee289b 100644 --- a/maildir/shared.c +++ b/maildir/shared.c @@ -1164,6 +1164,9 @@ int mh_rewrite_message(struct Mailbox *m, int msgno) */ void maildir_canon_filename(struct Buffer *dest, const char *src) { + if (!dest || !src) + return; + char *t = strrchr(src, '/'); if (t) src = t + 1; diff --git a/mutt/envlist.c b/mutt/envlist.c index 075b3f78c..98ec51ab5 100644 --- a/mutt/envlist.c +++ b/mutt/envlist.c @@ -105,7 +105,7 @@ bool mutt_envlist_set(const char *name, const char *value, bool overwrite) } /* Format var=value string */ - snprintf(work, sizeof(work), "%s=%s", NONULL(name), NONULL(value)); + snprintf(work, sizeof(work), "%s=%s", name, NONULL(value)); if (envp && *envp) { diff --git a/mutt/regex.c b/mutt/regex.c index e0e4e6658..fbb0fdfaa 100644 --- a/mutt/regex.c +++ b/mutt/regex.c @@ -56,7 +56,7 @@ struct Regex *mutt_regex_compile(const char *str, int flags) struct Regex *rx = mutt_mem_calloc(1, sizeof(struct Regex)); rx->pattern = mutt_str_strdup(str); rx->regex = mutt_mem_calloc(1, sizeof(regex_t)); - if (REG_COMP(rx->regex, NONULL(str), flags) != 0) + if (REG_COMP(rx->regex, str, flags) != 0) mutt_regex_free(&rx); return rx; diff --git a/muttlib.c b/muttlib.c index 8d14e899a..b1f575876 100644 --- a/muttlib.c +++ b/muttlib.c @@ -613,6 +613,9 @@ void mutt_mktemp_full(char *buf, size_t buflen, const char *prefix, */ void mutt_pretty_mailbox(char *buf, size_t buflen) { + if (!buf) + return; + char *p = buf, *q = buf; size_t len; enum UrlScheme scheme; @@ -682,15 +685,16 @@ void mutt_pretty_mailbox(char *buf, size_t buflen) /** * mutt_buffer_pretty_mailbox - Shorten a mailbox path using '~' or '=' - * @param s Buffer containing Mailbox name + * @param buf Buffer containing Mailbox name */ -void mutt_buffer_pretty_mailbox(struct Buffer *s) +void mutt_buffer_pretty_mailbox(struct Buffer *buf) { + if (!buf || !buf->data) /* This reduces the size of the Buffer, so we can pass it through. - * We adjust the size just to make sure s->data is not NULL though */ - mutt_buffer_increase_size(s, PATH_MAX); - mutt_pretty_mailbox(s->data, s->dsize); - mutt_buffer_fix_dptr(s); + * We adjust the size just to make sure buf->data is not NULL though */ + mutt_buffer_increase_size(buf, PATH_MAX); + mutt_pretty_mailbox(buf->data, buf->dsize); + mutt_buffer_fix_dptr(buf); } /** diff --git a/pattern.c b/pattern.c index a1e3beee3..e8919c411 100644 --- a/pattern.c +++ b/pattern.c @@ -1386,7 +1386,7 @@ static struct PatternHead *mutt_pattern_node_new(void) * @param err Buffer for error messages * @retval ptr Newly allocated Pattern */ -struct PatternHead *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer *err) +struct PatternHead *mutt_pattern_comp(const char *s, int flags, struct Buffer *err) { /* curlist when assigned will always point to a list containing at least one node * with a Pattern value. */ @@ -1405,7 +1405,7 @@ struct PatternHead *mutt_pattern_comp(/* const */ char *s, int flags, struct Buf struct Buffer ps; mutt_buffer_init(&ps); - ps.dptr = s; + ps.dptr = (char *) s; ps.dsize = mutt_str_strlen(s); while (*ps.dptr) diff --git a/pattern.h b/pattern.h index 13b73aaea..55cc5a4d9 100644 --- a/pattern.h +++ b/pattern.h @@ -150,7 +150,7 @@ enum PatternType int mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache); -struct PatternHead *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer *err); +struct PatternHead *mutt_pattern_comp(const char *s, int flags, struct Buffer *err); void mutt_check_simple(struct Buffer *s, const char *simple); void mutt_pattern_free(struct PatternHead **pat); -- 2.40.0