]> granicus.if.org Git - neomutt/commitdiff
Do not cast or check returns from safe_calloc (#396)
authorPietro Cerutti <gahr@gahr.ch>
Mon, 13 Feb 2017 12:38:36 +0000 (12:38 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 13 Feb 2017 12:38:36 +0000 (12:38 +0000)
Fixes #388

16 files changed:
browser.c
buffy.c
compose.c
handler.c
imap/util.c
init.c
menu.c
mutt_notmuch.c
mutt_socket.c
mutt_ssl.c
mutt_ssl_gnutls.c
pager.c
query.c
recvattach.c
rfc1524.c
smime.c

index 1eb232408be1db529668ca9e87ada03c94dba644..36c7282880aa5e1c80c2f29b04d069bd498443c4 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -604,7 +604,7 @@ static void init_state (struct browser_state *state, MUTTMENU *menu)
 {
   state->entrylen = 0;
   state->entrymax = 256;
-  state->entry = (struct folder_file *) safe_calloc (state->entrymax, sizeof (struct folder_file));
+  state->entry = safe_calloc (state->entrymax, sizeof (struct folder_file));
 #ifdef USE_IMAP
   state->imap_browse = 0;
 #endif
diff --git a/buffy.c b/buffy.c
index e33d76ca546ba00253f5f00282ddd3074212ec3d..c33373988077b4c1fbd7d7fe0ce198123f36013e 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -209,7 +209,7 @@ static BUFFY *buffy_new (const char *path)
   char rp[PATH_MAX] = "";
   char *r = NULL;
 
-  buffy = (BUFFY *) safe_calloc (1, sizeof (BUFFY));
+  buffy = safe_calloc (1, sizeof (BUFFY));
   strfcpy (buffy->path, path, sizeof (buffy->path));
   r = realpath (path, rp);
   strfcpy (buffy->realpath, r ? rp : path, sizeof (buffy->realpath));
index 83eb6a47992e8565653da137693eace7edfdcc2f..440f3aac73614848a4e6a036d3a8854503d37cce 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -791,7 +791,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          menu->data = idx;
        }
        
-       idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
+       idx[idxlen] = safe_calloc (1, sizeof (ATTACHPTR));
        if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
        {
          update_idx (menu, idx, idxlen++);
@@ -839,7 +839,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          for (i = 0; i < numfiles; i++)
          {
            char *att = files[i];
-           idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
+           idx[idxlen] = safe_calloc (1, sizeof (ATTACHPTR));
             idx[idxlen]->unowned = 1;
            idx[idxlen]->content = mutt_make_file_attach (att);
            if (idx[idxlen]->content != NULL)
@@ -965,7 +965,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
            h = Context->hdrs[i];
            if (h->tagged)
            {
-             idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
+             idx[idxlen] = safe_calloc (1, sizeof (ATTACHPTR));
              idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
              if (idx[idxlen]->content != NULL)
                update_idx (menu, idx, idxlen++);
@@ -1273,16 +1273,15 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
            menu->data = idx;
          }
 
-         idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
          /* Touch the file */
          if (!(fp = safe_fopen (fname, "w")))
          {
            mutt_error (_("Can't create file %s"), fname);
-           FREE (&idx[idxlen]);
            continue;
          }
          safe_fclose (&fp);
 
+         idx[idxlen] = safe_calloc (1, sizeof (ATTACHPTR));
          if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL)
          {
            mutt_error (_("What we have here is a failure to make an attachment"));
index 431801f36d19b91fb004110d64dabc65c4b4d5af..a23f3c1d3b22a6ed4e75c66487e15b61cf8ee070 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -794,8 +794,8 @@ static int text_enriched_handler (BODY *a, STATE *s)
   stte.WrapMargin = ((s->flags & MUTT_DISPLAY) ? (MuttIndexWindow->cols-4) :
                      ((MuttIndexWindow->cols-4)<72)?(MuttIndexWindow->cols-4):72);
   stte.line_max = stte.WrapMargin * 4;
-  stte.line = (wchar_t *) safe_calloc (1, (stte.line_max + 1) * sizeof (wchar_t));
-  stte.param = (wchar_t *) safe_calloc (1, (STRING) * sizeof (wchar_t));
+  stte.line = safe_calloc (1, (stte.line_max + 1) * sizeof (wchar_t));
+  stte.param = safe_calloc (1, (STRING) * sizeof (wchar_t));
 
   stte.param_len = STRING;
   stte.param_used = 0;
index fa4c974ff767eb90f2e265449252603ab3616b6b..781118bad26a55dad0ea5823011efe336c90be1f 100644 (file)
@@ -472,9 +472,6 @@ IMAP_DATA* imap_new_idata (void)
 {
   IMAP_DATA* idata = safe_calloc (1, sizeof (IMAP_DATA));
 
-  if (!idata)
-    return NULL;
-
   if (!(idata->cmdbuf = mutt_buffer_new ()))
     FREE (&idata);
 
diff --git a/init.c b/init.c
index 8a5f9a898d6bc9ec9171693f3e709f4a2f65e6f4..6b183aac14d232aea4ceca8d19be6d13496785eb 100644 (file)
--- a/init.c
+++ b/init.c
@@ -405,7 +405,7 @@ static void add_to_list (LIST **list, const char *str)
 
   if (!*list || last)
   {
-    t = (LIST *) safe_calloc (1, sizeof (LIST));
+    t = safe_calloc (1, sizeof (LIST));
     t->data = safe_strdup (str);
     if (last)
     {
@@ -1588,7 +1588,7 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
   if (!tmp)
   {
     /* create a new alias */
-    tmp = (ALIAS *) safe_calloc (1, sizeof (ALIAS));
+    tmp = safe_calloc (1, sizeof (ALIAS));
     tmp->self = tmp;
     tmp->name = safe_strdup (buf->data);
     /* give the main addressbook code a chance */
diff --git a/menu.c b/menu.c
index e7f9b5d95c903534eb9390fa47f523dca3fb4158..3fd55fae55a55349c2c82fc7535171c247240ca4 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -757,7 +757,7 @@ void mutt_menu_init (void)
 
 MUTTMENU *mutt_new_menu (int menu)
 {
-  MUTTMENU *p = (MUTTMENU *) safe_calloc (1, sizeof (MUTTMENU));
+  MUTTMENU *p = safe_calloc (1, sizeof (MUTTMENU));
 
   if ((menu < 0) || (menu >= MENU_MAX))
     menu = MENU_GENERIC;
index c686e8cae276d33962098a93fab8dd9a4a43afb6..aa6bafe8d39cb07c0ddb37322fc18f35679e256e 100644 (file)
@@ -265,8 +265,6 @@ static int url_parse_query(const char *url, char **filename, struct uri_tag **ta
   while (p && *p)
   {
     tag = safe_calloc(1, sizeof(struct uri_tag));
-    if (!tag)
-      goto err;
 
     if (!*tags)
       last = *tags = tag;
index 3cef4e54e774aee3187ae4187fb94fa08029f20b..5995f7c158ccd005edc57ce7abc0271190f9957b 100644 (file)
@@ -381,7 +381,7 @@ static CONNECTION* socket_new_conn (void)
 {
   CONNECTION* conn;
 
-  conn = (CONNECTION *) safe_calloc (1, sizeof (CONNECTION));
+  conn = safe_calloc (1, sizeof (CONNECTION));
   conn->fd = -1;
 
   return conn;
index cf2529820326d37038792025f0cae9a1925347c1..3f7258803611d24d457a75be621ed5e9954a32fd 100644 (file)
@@ -97,7 +97,7 @@ int mutt_ssl_starttls (CONNECTION* conn)
   if (ssl_init())
     goto bail;
 
-  ssldata = (sslsockdata*) safe_calloc (1, sizeof (sslsockdata));
+  ssldata = safe_calloc (1, sizeof (sslsockdata));
   /* the ssl_use_xxx protocol options don't apply. We must use TLS in TLS.
    *
    * However, we need to be able to negotiate amongst various TLS versions,
@@ -350,7 +350,7 @@ static int ssl_socket_open (CONNECTION * conn)
   if (raw_socket_open (conn) < 0)
     return -1;
 
-  data = (sslsockdata *) safe_calloc (1, sizeof (sslsockdata));
+  data = safe_calloc (1, sizeof (sslsockdata));
   conn->sockdata = data;
 
   if (! (data->ctx = SSL_CTX_new (SSLv23_client_method ())))
@@ -991,9 +991,9 @@ static int interactive_check_cert (X509 *cert, int idx, int len)
   FILE *fp;
 
   menu->max = mutt_array_size (part) * 2 + 9;
-  menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *));
+  menu->dialog = safe_calloc (1, menu->max * sizeof (char *));
   for (i = 0; i < menu->max; i++)
-    menu->dialog[i] = (char *) safe_calloc (1, SHORT_STRING * sizeof (char));
+    menu->dialog[i] = safe_calloc (1, SHORT_STRING * sizeof (char));
 
   row = 0;
   strfcpy (menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING);
index 95b0600121e7d3305a8d961c145ae26801f9debe..aa61d9d04cb401cabe09a5fe88fc1de273729f95 100644 (file)
@@ -375,7 +375,7 @@ static int tls_negotiate (CONNECTION * conn)
   tlssockdata *data;
   int err;
 
-  data = (tlssockdata *) safe_calloc (1, sizeof (tlssockdata));
+  data = safe_calloc (1, sizeof (tlssockdata));
   conn->sockdata = data;
   err = gnutls_certificate_allocate_credentials (&data->xcred);
   if (err < 0)
@@ -533,7 +533,7 @@ static int tls_compare_certificates (const gnutls_datum_t *peercert)
     return 0;
 
   b64_data.size = filestat.st_size+1;
-  b64_data_data = (unsigned char *) safe_calloc (1, b64_data.size);
+  b64_data_data = safe_calloc (1, b64_data.size);
   b64_data_data[b64_data.size-1] = '\0';
   b64_data.data = b64_data_data;
 
@@ -854,9 +854,9 @@ static int tls_check_one_certificate (const gnutls_datum_t *certdata,
 
   menu = mutt_new_menu (MENU_GENERIC);
   menu->max = 25;
-  menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *));
+  menu->dialog = safe_calloc (1, menu->max * sizeof (char *));
   for (i = 0; i < menu->max; i++)
-    menu->dialog[i] = (char *) safe_calloc (1, SHORT_STRING * sizeof (char));
+    menu->dialog[i] = safe_calloc (1, SHORT_STRING * sizeof (char));
 
   row = 0;
   strfcpy (menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING);
diff --git a/pager.c b/pager.c
index b0dfe9e435410ee1c74af32a7ddd30bfbbd2eb3b..5de348bee22ca555f459db5c0e5f2a35b0294f3d 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -407,7 +407,7 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr,
 
     if (*QuoteList == NULL)
     {
-      class = (struct q_class_t *) safe_calloc (1, sizeof (struct q_class_t));
+      class = safe_calloc (1, sizeof (struct q_class_t));
       class->color = ColorQuote[0];
       *QuoteList = class;
     }
@@ -432,8 +432,8 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr,
        if (tmp == NULL)
        {
          /* add a node above q_list */
-         tmp = (struct q_class_t *) safe_calloc (1, sizeof (struct q_class_t));
-         tmp->prefix = (char *) safe_calloc (1, length + 1);
+         tmp = safe_calloc (1, sizeof (struct q_class_t));
+         tmp->prefix = safe_calloc (1, length + 1);
          strncpy (tmp->prefix, qptr, length);
          tmp->length = length;
 
@@ -542,9 +542,8 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr,
              if (tmp == NULL)
              {
                /* add a node above q_list */
-               tmp = (struct q_class_t *) safe_calloc (1, 
-                                           sizeof (struct q_class_t));
-               tmp->prefix = (char *) safe_calloc (1, length + 1);
+               tmp = safe_calloc (1, sizeof (struct q_class_t));
+               tmp->prefix = safe_calloc (1, length + 1);
                strncpy (tmp->prefix, qptr, length);
                tmp->length = length;
                        
@@ -645,8 +644,8 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr,
        /* still not found so far: add it as a sibling to the current node */
        if (class == NULL)
        {
-         tmp = (struct q_class_t *) safe_calloc (1, sizeof (struct q_class_t));
-         tmp->prefix = (char *) safe_calloc (1, length + 1);
+         tmp = safe_calloc (1, sizeof (struct q_class_t));
+         tmp->prefix = safe_calloc (1, length + 1);
          strncpy (tmp->prefix, qptr, length);
          tmp->length = length;
 
@@ -682,8 +681,8 @@ classify_quote (struct q_class_t **QuoteList, const char *qptr,
   if (class == NULL)
   {
     /* not found so far: add it as a top level class */
-    class = (struct q_class_t *) safe_calloc (1, sizeof (struct q_class_t));
-    class->prefix = (char *) safe_calloc (1, length + 1);
+    class = safe_calloc (1, sizeof (struct q_class_t));
+    class->prefix = safe_calloc (1, length + 1);
     strncpy (class->prefix, qptr, length);
     class->length = length;
     new_class_color (class, q_level);
@@ -1753,10 +1752,10 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
     snprintf (helpstr, sizeof (helpstr), "%s %s", tmphelp, buffer);
   }
 
-  index_status_window = safe_calloc (sizeof (mutt_window_t), 1);
-  index_window        = safe_calloc (sizeof (mutt_window_t), 1);
-  pager_status_window = safe_calloc (sizeof (mutt_window_t), 1);
-  pager_window        = safe_calloc (sizeof (mutt_window_t), 1);
+  index_status_window = safe_calloc (1, sizeof (mutt_window_t));
+  index_window        = safe_calloc (1, sizeof (mutt_window_t));
+  pager_status_window = safe_calloc (1, sizeof (mutt_window_t));
+  pager_window        = safe_calloc (1, sizeof (mutt_window_t));
 
   while (ch != -1)
   {
diff --git a/query.c b/query.c
index a84b0c7a3ef390d15bb256eac7ef50a77c8e4e50..cfdbb27e6c9789d3b4f6a67d691cdd08bf2cfa40 100644 (file)
--- a/query.c
+++ b/query.c
@@ -121,12 +121,12 @@ static QUERY *run_query (char *s, int quiet)
     {
       if (first == NULL)
       {
-       first = (QUERY *) safe_calloc (1, sizeof (QUERY));
+       first = safe_calloc (1, sizeof (QUERY));
        cur = first;
       }
       else
       {
-       cur->next = (QUERY *) safe_calloc (1, sizeof (QUERY));
+       cur->next = safe_calloc (1, sizeof (QUERY));
        cur = cur->next;
       }
 
@@ -344,7 +344,7 @@ static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf)
     for (queryp = results; queryp; queryp = queryp->next)
       menu->max++;
 
-    menu->data = QueryTable = (ENTRY *) safe_calloc (menu->max, sizeof (ENTRY));
+    menu->data = QueryTable = safe_calloc (menu->max, sizeof (ENTRY));
 
     for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
       QueryTable[i].data = queryp;
@@ -396,8 +396,7 @@ static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf)
 
              if (op == OP_QUERY)
              {
-               menu->data = QueryTable = 
-                 (ENTRY *) safe_calloc (menu->max, sizeof (ENTRY));
+               menu->data = QueryTable = safe_calloc (menu->max, sizeof (ENTRY));
 
                for (i = 0, queryp = results; queryp; 
                     queryp = queryp->next, i++)
index 6655eee13832709fc047eabe5877102f5bc10c61..3e5c1fb5e29b78ceb8b5bd19a29051a6bb712b0d 100644 (file)
@@ -128,7 +128,7 @@ ATTACHPTR **mutt_gen_attach_list (BODY *m,
     else
     {
       if (!idx[*idxlen])
-       idx[*idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
+       idx[*idxlen] = safe_calloc (1, sizeof (ATTACHPTR));
 
       new = idx[(*idxlen)++];
       new->content = m;
index 52ea9b70e15ca8742fd426dcd013b4e975d52203..264a0de76ec5ff75293bc36573c08d1a9ce31401 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -355,7 +355,7 @@ static int rfc1524_mailcap_parse (BODY *a,
 
 rfc1524_entry *rfc1524_new_entry(void)
 {
-  return (rfc1524_entry *)safe_calloc(1, sizeof(rfc1524_entry));
+  return safe_calloc(1, sizeof(rfc1524_entry));
 }
 
 void rfc1524_free_entry(rfc1524_entry **entry)
diff --git a/smime.c b/smime.c
index b2a0249ebbaa983fd2cdf9b1f1e4fda796efce26..117ea6a9e68c160b16b5a24a806bccbdb43cab82 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -100,7 +100,7 @@ static smime_key_t *smime_copy_key (smime_key_t *key)
   if (!key)
     return NULL;
 
-  copy = safe_calloc (sizeof (smime_key_t), 1);
+  copy = safe_calloc (1, sizeof (smime_key_t));
   copy->email  = safe_strdup(key->email);
   copy->hash   = safe_strdup(key->hash);
   copy->label  = safe_strdup(key->label);
@@ -506,7 +506,7 @@ static smime_key_t *smime_parse_key(char *buf)
   char *pend, *p;
   int field = 0;
 
-  key = safe_calloc (sizeof (smime_key_t), 1);
+  key = safe_calloc (1, sizeof (smime_key_t));
 
   for (p = buf; p; p = pend)
   {
@@ -999,7 +999,7 @@ static int smime_handle_cert_email (char *certificate, char *mailbox,
   if(copy && buffer && num)
   {
     (*num) = count;
-    *buffer =  safe_calloc(sizeof(char*), count);
+    *buffer =  safe_calloc(count, sizeof(char*));
     count = 0;
 
     rewind (fpout);
@@ -1008,7 +1008,7 @@ static int smime_handle_cert_email (char *certificate, char *mailbox,
       len = mutt_strlen (email);
       if (len && (email[len - 1] == '\n'))
         email[len - 1] = '\0';
-      (*buffer)[count] = safe_calloc(1, mutt_strlen (email) + 1);
+      (*buffer)[count] = safe_calloc(mutt_strlen (email) + 1, sizeof(char));
       strncpy((*buffer)[count], email, mutt_strlen (email));
       count++;
     }