]> granicus.if.org Git - neomutt/commitdiff
fix coverity warnings
authorRichard Russon <rich@flatcap.org>
Fri, 6 Jan 2017 13:20:06 +0000 (13:20 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 12 Jan 2017 11:51:27 +0000 (11:51 +0000)
Closes: #286
crypt-gpgme.c
hcache-lmdb.c
hcache.c
imap/command.c
mutt_notmuch.c
pattern.c
pop_lib.c
sidebar.c
sort.c
system.c

index ca8149a43629743ab3113e7a5b1c464b21542356..c3cea0bb2c4ee5d12d0978d8bfb61fcd142fa137 100644 (file)
@@ -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);
index 5af171667a0302940201eb24413ace82baf81a16..06e58097da7eaceec6a10b84b2a4d0c4466084cd 100644 (file)
@@ -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;
   }
 
index 85dde3a6895a1a3b1921f182519b7eea0c3bbf92..052f780c903f0a1461fb6633e51e484c8284b616 100644 (file)
--- 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)
index 5177475bd2af890154c068d7b6fed54b90ba8ca6..7dde20f9a7cf80bcb2a8c623fb6ac6109af6246c 100644 (file)
@@ -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);
index ebbea401d60c118073bd04780ebba6f4e91eda65..08a47c3d5627f2828af7c9205bc2ef542dc1b5bf 100644 (file)
@@ -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 */
index 7750151a9d3e6f9b6c910addacc38db524ac9d58..77ca6031e026c76dd1e89a4472c06a27ba8b2160 100644 (file)
--- 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:
       {
index 44eb333eeaba78960e5dc16975c5b817e788cf7c..b35919abc1e8d9f067842fcf95350e5a3c2f0164 100644 (file)
--- 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)
index b2f92b0b890ae1466dac3f7fc3335d7a55a6f3ab..c497ff353d17370883288b7e799ed8bf4b12f2bf 100644 (file)
--- 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 9b1db9f1be78affc0f34ad818c3a026d074b99e1..85b7d881353735ccc86e1da7e364d637779f9c1b 100644 (file)
--- 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));
index 97dc2a8e79732c47398e0d9d8f5115f10f6da44d..80b25a18ad1092bc422d80872af53c4a0666173d 100644 (file)
--- 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);