From d2a6a8a565a92e006b8cc9da2f5172c92206aa84 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Tue, 7 Feb 2017 09:27:06 +0000 Subject: [PATCH] Do not cast return values from malloc (et similia) Closes #372 --- alias.c | 4 ++-- browser.c | 4 ++-- color.c | 4 ++-- curs_main.c | 2 +- hash.c | 2 +- init.c | 2 +- lib.c | 8 ++++---- mutt_sasl.c | 2 +- mutt_tunnel.c | 2 +- muttlib.c | 2 +- pgppubring.c | 2 +- regex.c | 29 +++++++++++++---------------- smime.c | 2 +- 13 files changed, 31 insertions(+), 34 deletions(-) diff --git a/alias.c b/alias.c index 11e614cef..6d1468a2e 100644 --- a/alias.c +++ b/alias.c @@ -539,10 +539,10 @@ int mutt_alias_complete (char *s, size_t buflen) if (a->name && (strstr (a->name, s) == a->name)) { if (!a_list) /* init */ - a_cur = a_list = (ALIAS *) safe_malloc (sizeof (ALIAS)); + a_cur = a_list = safe_malloc (sizeof (ALIAS)); else { - a_cur->next = (ALIAS *) safe_malloc (sizeof (ALIAS)); + a_cur->next = safe_malloc (sizeof (ALIAS)); a_cur = a_cur->next; } memcpy (a_cur, a, sizeof (ALIAS)); diff --git a/browser.c b/browser.c index 24256d0ee..dc3dd6be1 100644 --- a/browser.c +++ b/browser.c @@ -1649,7 +1649,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num strfcpy (buf, NONULL(Mask.pattern), sizeof (buf)); if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) { - regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); + regex_t *rx = safe_malloc (sizeof (regex_t)); char *s = buf; int not = 0, err; @@ -1966,7 +1966,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num { NNTP_SERVER *nserv = CurrentNewsSrv; NNTP_DATA *nntp_data; - regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); + regex_t *rx = safe_malloc (sizeof (regex_t)); char *s = buf; int rc, j = menu->current; diff --git a/color.c b/color.c index 79b5b3446..59ccb68e0 100644 --- a/color.c +++ b/color.c @@ -167,7 +167,7 @@ static void mutt_free_color_line(COLOR_LINE **l, void ci_start_color (void) { memset (ColorDefs, A_NORMAL, sizeof (int) * MT_COLOR_MAX); - ColorQuote = (int *) safe_malloc (COLOR_QUOTE_INIT * sizeof (int)); + ColorQuote = safe_malloc (COLOR_QUOTE_INIT * sizeof (int)); memset (ColorQuote, A_NORMAL, sizeof (int) * COLOR_QUOTE_INIT); ColorQuoteSize = COLOR_QUOTE_INIT; ColorQuoteUsed = 0; @@ -267,7 +267,7 @@ int mutt_alloc_color (int fg, int bg) i++; } - p = (COLOR_LIST *) safe_malloc (sizeof (COLOR_LIST)); + p = safe_malloc (sizeof (COLOR_LIST)); p->next = ColorList; ColorList = p; diff --git a/curs_main.c b/curs_main.c index ac2f02211..6ca4c29a2 100644 --- a/curs_main.c +++ b/curs_main.c @@ -484,7 +484,7 @@ void update_index (MUTTMENU *menu, CONTEXT *ctx, int check, if (option(OPTUNCOLLAPSENEW) && oldcount && check != MUTT_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) { - save_new = (HEADER **) safe_malloc (sizeof (HEADER *) * (ctx->msgcount - oldcount)); + save_new = safe_malloc (sizeof (HEADER *) * (ctx->msgcount - oldcount)); for (j = oldcount; j < ctx->msgcount; j++) save_new[j-oldcount] = ctx->hdrs[j]; } diff --git a/hash.c b/hash.c index d7ffc55ee..a3586d8e2 100644 --- a/hash.c +++ b/hash.c @@ -105,7 +105,7 @@ int hash_insert (HASH * table, const char *key, void *data, int allow_dup) struct hash_elem *ptr; unsigned int h; - ptr = (struct hash_elem *) safe_malloc (sizeof (struct hash_elem)); + ptr = safe_malloc (sizeof (struct hash_elem)); h = table->hash_string ((unsigned char *) key, table->nelem); ptr->key = key; ptr->data = data; diff --git a/init.c b/init.c index 168c9f0e9..7d1b97682 100644 --- a/init.c +++ b/init.c @@ -2310,7 +2310,7 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) } } - rx = (regex_t *) safe_malloc (sizeof (regex_t)); + rx = safe_malloc (sizeof (regex_t)); if ((e = REGCOMP (rx, p, flags)) != 0) { regerror (e, rx, err->data, err->dsize); diff --git a/lib.c b/lib.c index c6b1a1265..84ffc94d6 100644 --- a/lib.c +++ b/lib.c @@ -148,7 +148,7 @@ void *safe_malloc (size_t siz) if (siz == 0) return 0; - if ((p = (void *) malloc (siz)) == 0) /* __MEM_CHECKED__ */ + if ((p = malloc (siz)) == 0) /* __MEM_CHECKED__ */ { mutt_error _("Out of memory!"); sleep (1); @@ -173,11 +173,11 @@ void safe_realloc (void *ptr, size_t siz) } if (*p) - r = (void *) realloc (*p, siz); /* __MEM_CHECKED__ */ + r = realloc (*p, siz); /* __MEM_CHECKED__ */ else { /* realloc(NULL, nbytes) doesn't seem to work under SunOS 4.1.x --- __MEM_CHECKED__ */ - r = (void *) malloc (siz); /* __MEM_CHECKED__ */ + r = malloc (siz); /* __MEM_CHECKED__ */ } if (!r) @@ -239,7 +239,7 @@ char *safe_strdup (const char *s) if (!s || !*s) return 0; l = strlen (s) + 1; - p = (char *)safe_malloc (l); + p = safe_malloc (l); memcpy (p, s, l); return (p); } diff --git a/mutt_sasl.c b/mutt_sasl.c index 39aa8bd74..52a5649e3 100644 --- a/mutt_sasl.c +++ b/mutt_sasl.c @@ -345,7 +345,7 @@ int mutt_sasl_interact (sasl_interact_t* interaction) * for the read/write methods. */ void mutt_sasl_setup_conn (CONNECTION* conn, sasl_conn_t* saslconn) { - SASL_DATA* sasldata = (SASL_DATA*) safe_malloc (sizeof (SASL_DATA)); + SASL_DATA* sasldata = safe_malloc (sizeof (SASL_DATA)); /* work around sasl_getprop aliasing issues */ const void* tmp; diff --git a/mutt_tunnel.c b/mutt_tunnel.c index e199e07bc..e5af7d70c 100644 --- a/mutt_tunnel.c +++ b/mutt_tunnel.c @@ -67,7 +67,7 @@ static int tunnel_socket_open (CONNECTION *conn) int pin[2], pout[2]; int devnull; - tunnel = (TUNNEL_DATA*) safe_malloc (sizeof (TUNNEL_DATA)); + tunnel = safe_malloc (sizeof (TUNNEL_DATA)); conn->sockdata = tunnel; mutt_message (_("Connecting with \"%s\"..."), Tunnel); diff --git a/muttlib.c b/muttlib.c index d12c87ad3..7260e4546 100644 --- a/muttlib.c +++ b/muttlib.c @@ -371,7 +371,7 @@ LIST *mutt_copy_list (LIST *p) for (; p; p = p->next) { - t = (LIST *) safe_malloc (sizeof (LIST)); + t = safe_malloc (sizeof (LIST)); t->data = safe_strdup (p->data); t->next = NULL; if (l) diff --git a/pgppubring.c b/pgppubring.c index b045518f2..043732026 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -161,7 +161,7 @@ static char *binary_fingerprint_to_string (unsigned char *buff, size_t length) int i; char *fingerprint, *pf; - pf = fingerprint = (char *)safe_malloc ((length * 2) + 1); + pf = fingerprint = safe_malloc ((length * 2) + 1); for (i = 0; i < length; i++) { diff --git a/regex.c b/regex.c index 00f65b83c..364e9d249 100644 --- a/regex.c +++ b/regex.c @@ -362,8 +362,8 @@ char *alloca (); (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) /* (Re)Allocate N items of type T using malloc, or fail. */ -#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) -#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) +#define TALLOC(n, t) (malloc ((n) * sizeof (t))) +#define RETALLOC(addr, n, t) ((addr) = realloc (addr, (n) * sizeof (t))) #define RETALLOC_IF(addr, n, t) \ if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t) #define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) @@ -1149,7 +1149,7 @@ typedef struct #ifdef MATCH_MAY_ALLOCATE #define INIT_FAIL_STACK() \ do { \ - fail_stack.stack = (fail_stack_elt_t *) \ + fail_stack.stack = \ REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ \ if (fail_stack.stack == NULL) \ @@ -1180,7 +1180,7 @@ typedef struct #define DOUBLE_FAIL_STACK(fail_stack) \ ((fail_stack).size > (unsigned) (re_max_failures * MAX_FAILURE_ITEMS) \ ? 0 \ - : ((fail_stack).stack = (fail_stack_elt_t *) \ + : ((fail_stack).stack = \ REGEX_REALLOCATE_STACK ((fail_stack).stack, \ (fail_stack).size * sizeof (fail_stack_elt_t), \ ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ @@ -2900,14 +2900,12 @@ regex_compile (pattern, size, syntax, bufp) * sizeof (fail_stack_elt_t))); #else /* not emacs */ if (! fail_stack.stack) - fail_stack.stack - = (fail_stack_elt_t *) malloc (fail_stack.size /* __MEM_CHECKED__ */ - * sizeof (fail_stack_elt_t)); + fail_stack.stack = malloc (fail_stack.size /* __MEM_CHECKED__ */ + * sizeof (fail_stack_elt_t)); else - fail_stack.stack - = (fail_stack_elt_t *) realloc (fail_stack.stack, /* __MEM_CHECKED__ */ - (fail_stack.size - * sizeof (fail_stack_elt_t))); + fail_stack.stack = realloc (fail_stack.stack, /* __MEM_CHECKED__ */ + (fail_stack.size + * sizeof (fail_stack_elt_t))); #endif /* not emacs */ } @@ -5484,12 +5482,12 @@ re_comp (s) if (!re_comp_buf.buffer) { - re_comp_buf.buffer = (unsigned char *) malloc (200); /* __MEM_CHECKED__ */ + re_comp_buf.buffer = malloc (200); /* __MEM_CHECKED__ */ if (re_comp_buf.buffer == NULL) return gettext (re_error_msgid[(int) REG_ESPACE]); re_comp_buf.allocated = 200; - re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); /* __MEM_CHECKED__ */ + re_comp_buf.fastmap = malloc (1 << BYTEWIDTH); /* __MEM_CHECKED__ */ if (re_comp_buf.fastmap == NULL) return gettext (re_error_msgid[(int) REG_ESPACE]); } @@ -5588,9 +5586,8 @@ regcomp (preg, pattern, cflags) { unsigned i; - preg->translate - = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE /* __MEM_CHECKED__ */ - * sizeof (*(RE_TRANSLATE_TYPE)0)); + preg->translate = malloc (CHAR_SET_SIZE /* __MEM_CHECKED__ */ + * sizeof (*(RE_TRANSLATE_TYPE)0)); if (preg->translate == NULL) return (int) REG_ESPACE; diff --git a/smime.c b/smime.c index f1dd07751..0893b9b39 100644 --- a/smime.c +++ b/smime.c @@ -1503,7 +1503,7 @@ static char *openssl_md_to_smime_micalg(char *md) if (mutt_strncasecmp ("sha", md, 3) == 0) { l = strlen (md) + 2; - micalg = (char *)safe_malloc (l); + micalg = safe_malloc (l); snprintf (micalg, l, "sha-%s", md +3); } else -- 2.40.0