From: Pietro Cerutti Date: Mon, 13 Feb 2017 12:38:36 +0000 (+0000) Subject: Do not cast or check returns from safe_calloc (#396) X-Git-Tag: neomutt-20170225~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c92daeb8b1ebd3019069592c3d1af06ae25b3011;p=neomutt Do not cast or check returns from safe_calloc (#396) Fixes #388 --- diff --git a/browser.c b/browser.c index 1eb232408..36c728288 100644 --- 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 e33d76ca5..c33373988 100644 --- 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)); diff --git a/compose.c b/compose.c index 83eb6a479..440f3aac7 100644 --- 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")); diff --git a/handler.c b/handler.c index 431801f36..a23f3c1d3 100644 --- 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; diff --git a/imap/util.c b/imap/util.c index fa4c974ff..781118bad 100644 --- a/imap/util.c +++ b/imap/util.c @@ -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 8a5f9a898..6b183aac1 100644 --- 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 e7f9b5d95..3fd55fae5 100644 --- 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; diff --git a/mutt_notmuch.c b/mutt_notmuch.c index c686e8cae..aa6bafe8d 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -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; diff --git a/mutt_socket.c b/mutt_socket.c index 3cef4e54e..5995f7c15 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -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; diff --git a/mutt_ssl.c b/mutt_ssl.c index cf2529820..3f7258803 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -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); diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index 95b060012..aa61d9d04 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -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 b0dfe9e43..5de348bee 100644 --- 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 a84b0c7a3..cfdbb27e6 100644 --- 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++) diff --git a/recvattach.c b/recvattach.c index 6655eee13..3e5c1fb5e 100644 --- a/recvattach.c +++ b/recvattach.c @@ -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; diff --git a/rfc1524.c b/rfc1524.c index 52ea9b70e..264a0de76 100644 --- 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 b2a0249eb..117ea6a9e 100644 --- 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++; }