misc: never cast void* from malloc(3) and friends

Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
This commit is contained in:
Ruediger Meier 2016-02-26 11:10:24 +01:00
parent d9851e63fb
commit fea1cbf748
12 changed files with 15 additions and 15 deletions

View File

@ -87,7 +87,7 @@ static void init_signature_page(struct mkswap_control *ctl)
} else
ctl->pagesize = kernel_pagesize;
ctl->signature_page = (unsigned long *) xcalloc(1, ctl->pagesize);
ctl->signature_page = xcalloc(1, ctl->pagesize);
ctl->hdr = (struct swap_header_v1_2 *) ctl->signature_page;
}

View File

@ -33,7 +33,7 @@ void initproctitle (int argc, char **argv)
for (i = 0; envp[i] != NULL; i++)
continue;
environ = (char **) malloc(sizeof(char *) * (i + 1));
environ = malloc(sizeof(char *) * (i + 1));
if (environ == NULL)
return;

View File

@ -247,7 +247,7 @@ char *strnchr(const char *s, size_t maxlen, int c)
char *strndup(const char *s, size_t n)
{
size_t len = strnlen(s, n);
char *new = (char *) malloc((len + 1) * sizeof(char));
char *new = malloc((len + 1) * sizeof(char));
if (!new)
return NULL;
new[len] = '\0';

View File

@ -102,7 +102,7 @@ int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
DBG(CACHE, ul_debug("creating blkid cache (using %s)",
filename ? filename : "default cache"));
if (!(cache = (blkid_cache) calloc(1, sizeof(struct blkid_struct_cache))))
if (!(cache = calloc(1, sizeof(struct blkid_struct_cache))))
return -BLKID_ERR_MEM;
INIT_LIST_HEAD(&cache->bic_devs);

View File

@ -120,7 +120,7 @@ struct blkid_config *blkid_read_config(const char *filename)
if (!filename)
filename = BLKID_CONFIG_FILE;
conf = (struct blkid_config *) calloc(1, sizeof(*conf));
conf = calloc(1, sizeof(*conf));
if (!conf)
return NULL;
conf->uevent = -1;

View File

@ -34,7 +34,7 @@ blkid_dev blkid_new_dev(void)
{
blkid_dev dev;
if (!(dev = (blkid_dev) calloc(1, sizeof(struct blkid_struct_dev))))
if (!(dev = calloc(1, sizeof(struct blkid_struct_dev))))
return NULL;
INIT_LIST_HEAD(&dev->bid_devs);

View File

@ -21,7 +21,7 @@ static blkid_tag blkid_new_tag(void)
{
blkid_tag tag;
if (!(tag = (blkid_tag) calloc(1, sizeof(struct blkid_struct_tag))))
if (!(tag = calloc(1, sizeof(struct blkid_struct_tag))))
return NULL;
INIT_LIST_HEAD(&tag->bit_tags);

View File

@ -1039,7 +1039,7 @@ static void init_environ(struct login_context *cxt)
/* destroy environment unless user has requested preservation (-p) */
if (!cxt->keep_env) {
environ = (char **) xmalloc(sizeof(char *));
environ = xmalloc(sizeof(char *));
memset(environ, 0, sizeof(char *));
}

View File

@ -161,7 +161,7 @@ static void create_nthreads(process_t *proc, size_t index)
size_t i, ncreated = 0;
int rc;
threads = (thread_t *) xcalloc(nthreads, sizeof(thread_t));
threads = xcalloc(nthreads, sizeof(thread_t));
for (i = 0; i < nthreads; i++) {
thread_t *th = &threads[i];
@ -209,7 +209,7 @@ static void create_nprocesses(void)
process_t *process;
size_t i;
process = (process_t *) xcalloc(nprocesses, sizeof(process_t));
process = xcalloc(nprocesses, sizeof(process_t));
for (i = 0; i < nprocesses; i++) {
process_t *proc = &process[i];

View File

@ -86,7 +86,7 @@ static size_t ulct;
void add_label(const char *label)
{
llist = (const char **) xrealloc(llist, (++llct) * sizeof(char *));
llist = xrealloc(llist, (++llct) * sizeof(char *));
llist[llct - 1] = label;
}
@ -102,7 +102,7 @@ size_t numof_labels(void)
void add_uuid(const char *uuid)
{
ulist = (const char **) xrealloc(ulist, (++ulct) * sizeof(char *));
ulist = xrealloc(ulist, (++ulct) * sizeof(char *));
ulist[ulct - 1] = uuid;
}

View File

@ -1970,7 +1970,7 @@ static char *get_logname(struct options *op, struct termios *tp, struct chardata
if (len < 0)
log_err(_("%s: invalid character conversion for login name"), op->tty);
wcs = (wchar_t *) malloc((len + 1) * sizeof(wchar_t));
wcs = malloc((len + 1) * sizeof(wchar_t));
if (!wcs)
log_err(_("failed to allocate memory: %m"));

View File

@ -362,7 +362,7 @@ int main(int argc, char **argv)
int need;
need = l->l_lsize ? l->l_lsize * 2 : 90;
l->l_line = (CHAR *)xrealloc((void *) l->l_line,
l->l_line = xrealloc((void *) l->l_line,
(unsigned) need * sizeof(CHAR));
l->l_lsize = need;
}
@ -472,7 +472,7 @@ void flush_line(LINE *l)
*/
if (l->l_lsize > sorted_size) {
sorted_size = l->l_lsize;
sorted = (CHAR *)xrealloc((void *)sorted,
sorted = xrealloc((void *)sorted,
(unsigned)sizeof(CHAR) * sorted_size);
}
if (l->l_max_col >= count_size) {