From 489b2d2bcb1a717832bf1aa382128572dfb0e90d Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 6 Jan 2017 13:20:06 +0000 Subject: [PATCH] fix coverity warnings Closes: #286 --- crypt-gpgme.c | 16 +++++----------- hcache-lmdb.c | 1 + hcache.c | 18 ++++++------------ imap/command.c | 2 +- mutt_notmuch.c | 25 +++++++++++++++---------- pattern.c | 1 - pop_lib.c | 3 ++- sidebar.c | 2 +- sort.c | 2 ++ system.c | 7 +++++-- 10 files changed, 38 insertions(+), 39 deletions(-) diff --git a/crypt-gpgme.c b/crypt-gpgme.c index ca8149a43..c3cea0bb2 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -2097,13 +2097,13 @@ static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun) strftime (date, sizeof (date), "%Y-%m-%d", localtime (&tt)); if (!more) - fprintf (*fp, "%s %5.5s %d/%8s %s %s\n", more ? "sub" : "pub", + fprintf (*fp, "pub %5.5s %d/%8s %s %s\n", gpgme_pubkey_algo_name (subkey->pubkey_algo), subkey->length, shortid, date, uid->uid); else - fprintf (*fp, "%s %5.5s %d/%8s %s\n", more ? "sub" : "pub", + fprintf (*fp, "sub %5.5s %d/%8s %s\n", gpgme_pubkey_algo_name (subkey->pubkey_algo), subkey->length, - shortid, date); + shortid, date); subkey = subkey->next; more = 1; } @@ -3578,15 +3578,9 @@ static void print_key_info (gpgme_key_t key, FILE *fp) fprintf (fp, _("Valid To ..: %s\n"), shortbuf); } - if (subkey) - s = gpgme_pubkey_algo_name (subkey->pubkey_algo); - else - s = "?"; + s = gpgme_pubkey_algo_name (subkey->pubkey_algo); - if (subkey) - aval = subkey->length; - else - aval = 0; + aval = subkey->length; /* L10N: DOTFILL */ fprintf (fp, _("Key Type ..: %s, %lu bit %s\n"), "PGP", aval, s); diff --git a/hcache-lmdb.c b/hcache-lmdb.c index 5af171667..06e58097d 100644 --- a/hcache-lmdb.c +++ b/hcache-lmdb.c @@ -99,6 +99,7 @@ hcache_lmdb_open(const char *path) if (rc != MDB_SUCCESS) { fprintf(stderr, "hcache_open_lmdb: mdb_env_create: %s", mdb_strerror(rc)); + FREE(&ctx); return NULL; } diff --git a/hcache.c b/hcache.c index 85dde3a68..052f780c9 100644 --- a/hcache.c +++ b/hcache.c @@ -719,19 +719,14 @@ static char* get_foldername(const char *folder) { char *p = NULL; char path[_POSIX_PATH_MAX]; - struct stat st; mutt_encode_path (path, sizeof (path), folder); /* if the folder is local, canonify the path to avoid * to ensure equivalent paths share the hcache */ - if (stat (path, &st) == 0) - { - p = safe_malloc (PATH_MAX+1); - if (!realpath (path, p)) - mutt_str_replace (&p, path); - } else - p = safe_strdup (path); + p = safe_malloc (PATH_MAX+1); + if (!realpath (path, p)) + mutt_str_replace (&p, path); return p; } @@ -740,12 +735,11 @@ header_cache_t * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer) { const hcache_ops_t *ops = hcache_get_ops(); - header_cache_t *h = safe_calloc(1, sizeof (header_cache_t)); - struct stat sb; - if (!ops) return NULL; + header_cache_t *h = safe_calloc(1, sizeof (header_cache_t)); + /* Calculate the current hcache version from dynamic configuration */ if (hcachever == 0x0) { union { @@ -799,7 +793,7 @@ mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer) else { /* remove a possibly incompatible version */ - if (!stat (path, &sb) && !unlink (path)) + if (unlink (path) == 0) { h->ctx = ops->open(path); if (h->ctx) diff --git a/imap/command.c b/imap/command.c index 5177475bd..7dde20f9a 100644 --- a/imap/command.c +++ b/imap/command.c @@ -782,7 +782,7 @@ static void cmd_parse_lsub (IMAP_DATA* idata, char* s) url.path[strlen(url.path) - 1] = '\0'; if (!mutt_strcmp (url.user, ImapUser)) url.user = NULL; - url_ciss_tostring (&url, buf + 11, sizeof (buf) - 10, 0); + url_ciss_tostring (&url, buf + 11, sizeof (buf) - 11, 0); safe_strcat (buf, sizeof (buf), "\""); mutt_buffer_init (&token); mutt_buffer_init (&err); diff --git a/mutt_notmuch.c b/mutt_notmuch.c index ebbea401d..08a47c3d5 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -152,12 +152,10 @@ static int url_parse_query(char *url, char **filename, struct uri_tag **tags) *filename = e ? e == p ? NULL : strndup(p, e - p) : safe_strdup(p); if (!e) - return 0; + return 0; /* only filename */ if (*filename && url_pct_decode(*filename) < 0) goto err; - if (!e) - return 0; /* only filename */ ++e; /* skip '?' */ p = e; @@ -269,9 +267,7 @@ static struct nm_ctxdata *new_ctxdata(char *uri) if (url_parse_query(uri, &data->db_filename, &data->query_items)) { mutt_error(_("failed to parse notmuch uri: %s"), uri); - data->db_filename = NULL; - data->query_items = NULL; - data->query_type = 0; + FREE(&data); return NULL; } @@ -924,6 +920,8 @@ static void nm_progress_reset(CONTEXT *ctx) return; data = get_ctxdata(ctx); + if (!data) + return; memset(&data->progress, 0, sizeof(data->progress)); data->oldmsgcount = ctx->msgcount; @@ -936,7 +934,7 @@ static void nm_progress_update(CONTEXT *ctx, notmuch_query_t *q) { struct nm_ctxdata *data = get_ctxdata(ctx); - if (ctx->quiet || data->noprogress) + if (ctx->quiet || !data || data->noprogress) return; if (!data->progress_ready && q) { @@ -970,9 +968,13 @@ static void append_message(CONTEXT *ctx, const char *path; HEADER *h = NULL; + struct nm_ctxdata *data = get_ctxdata(ctx); + if (!data) + return; + /* deduplicate */ if (dedup && get_mutt_header(ctx, msg)) { - get_ctxdata(ctx)->ignmsgcount++; + data->ignmsgcount++; nm_progress_update(ctx, q); dprint(2, (debugfile, "nm: ignore id=%s, already in the context\n", notmuch_message_get_message_id(msg))); @@ -1469,10 +1471,13 @@ static int rename_maildir_filename(const char *old, char *newpath, size_t newsz, strfcpy(folder, old, sizeof(folder)); p = strrchr(folder, '/'); - if (p) + if (p) { *p = '\0'; + p++; + } else { + p = folder; + } - p++; strfcpy(filename, p, sizeof(filename)); /* remove (new,cur,...) from folder path */ diff --git a/pattern.c b/pattern.c index 7750151a9..77ca6031e 100644 --- a/pattern.c +++ b/pattern.c @@ -1288,7 +1288,6 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, } return pat->not ^ result; } - return (pat->not ^ (h->env->x_label && patmatch (pat, h->env->x_label) == 0)); #ifdef USE_NOTMUCH case MUTT_NOTMUCH_LABEL: { diff --git a/pop_lib.c b/pop_lib.c index 44eb333ee..b35919abc 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -436,7 +436,8 @@ int pop_query_d (POP_DATA *pop_data, char *buf, size_t buflen, char *msg) mutt_socket_write_d (pop_data->conn, buf, -1, dbg); c = strpbrk (buf, " \r\n"); - *c = '\0'; + if (c) + *c = '\0'; snprintf (pop_data->err_msg, sizeof (pop_data->err_msg), "%s: ", buf); if (mutt_socket_readln (buf, buflen, pop_data->conn) < 0) diff --git a/sidebar.c b/sidebar.c index b2f92b0b8..c497ff353 100644 --- a/sidebar.c +++ b/sidebar.c @@ -532,7 +532,7 @@ static int prepare_sidebar (int page_size) */ static int draw_divider (int num_rows, int num_cols) { - if ((num_rows < 1) || (num_rows < 1)) + if ((num_rows < 1) || (num_cols < 1)) return 0; int i; diff --git a/sort.c b/sort.c index 9b1db9f1b..85b7d8813 100644 --- a/sort.c +++ b/sort.c @@ -220,7 +220,9 @@ static int compare_spam (const void *a, const void *b) { result = strcmp(aptr, bptr); if (result == 0) + { AUXSORT(result, a, b); + } } return (SORTCODE(result)); diff --git a/system.c b/system.c index 97dc2a8e7..80b25a18a 100644 --- a/system.c +++ b/system.c @@ -129,8 +129,11 @@ int _mutt_system (const char *cmd, int flags) #endif } - sigaction (SIGCONT, &oldcont, NULL); - sigaction (SIGTSTP, &oldtstp, NULL); + if (!(flags & MUTT_DETACH_PROCESS)) + { + sigaction (SIGCONT, &oldcont, NULL); + sigaction (SIGTSTP, &oldtstp, NULL); + } /* reset SIGINT, SIGQUIT and SIGCHLD */ mutt_unblock_signals_system (1); -- 2.50.1