]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: never cast void* from malloc(3) and friends
authorRuediger Meier <ruediger.meier@ga-group.nl>
Fri, 26 Feb 2016 10:10:24 +0000 (11:10 +0100)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Mon, 7 Mar 2016 22:29:27 +0000 (23:29 +0100)
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>
12 files changed:
disk-utils/mkswap.c
lib/setproctitle.c
lib/strutils.c
libblkid/src/cache.c
libblkid/src/config.c
libblkid/src/dev.c
libblkid/src/tag.c
login-utils/login.c
misc-utils/test_uuidd.c
sys-utils/swapon-common.c
term-utils/agetty.c
text-utils/col.c

index 52ee8c65dc89445a7590e4780b8e9188ea6bce44..a7c6a709b3f5e3378ad87bd0dca50b0457b7957e 100644 (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;
 }
 
index 4bcf8c8a96cf593037cf7a0bd05228e6774eb0d7..93bc82e4713a6f98d09390969b880d20363433c0 100644 (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;
 
index 64a6b992efd3026a414ccae37203af152a6c9de3..2d7cb59eda84d3f88e2ed2118ceabbb8fcb949b1 100644 (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';
index b576df8b4672113cee2ba4b0defc21c597829ad3..c6d02a48bb3706cb8e3607376deb9b5fa2bc7df3 100644 (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);
index 3c7f3124c2789aef202d503b7f81f163d7fd3f15..1822f1c678bc6f8b4506914a659e241a8ec69a47 100644 (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;
index 99b70b682f96c23fe755aaabf5681956fd852c81..8e5516bce6c368212bc91bde4033a54d28edb217 100644 (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);
index bfc7bb782a09cabf505f962a4230ca7e489068c4..4dc7da139391a8eb44c40bd409f8927239017959 100644 (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);
index ac76f656307e1e2a7eebcde935a60eda7770a939..236da9b3d8248056f7bf355bba0209ed8222f2a4 100644 (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 *));
        }
 
index 78399b91f00124e53f6f80d2a85467146692c281..36f3b3db2210c2cf5341c2d224563bb51dfeeaed 100644 (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];
index 75466a056bece2c767cbd54898cce020e124b027..8b686c0cd01b412b5d55b28f6622f805b2291ba1 100644 (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;
 }
 
index 55a00e125e56333adee64efb84844c49d435a829..1df1bc8612f0391b713e76acdc3cb039d70fd332 100644 (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"));
 
index 53f0556d3e26cd84c4463b4e11db40ab444685a6..0823573f45e22826e7ea1773abd9a945b0b4fa5a 100644 (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) {