Skip to content

Commit fea1cbf

Browse files
committed
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>
1 parent d9851e6 commit fea1cbf

12 files changed

Lines changed: 15 additions & 15 deletions

File tree

disk-utils/mkswap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void init_signature_page(struct mkswap_control *ctl)
8787
} else
8888
ctl->pagesize = kernel_pagesize;
8989

90-
ctl->signature_page = (unsigned long *) xcalloc(1, ctl->pagesize);
90+
ctl->signature_page = xcalloc(1, ctl->pagesize);
9191
ctl->hdr = (struct swap_header_v1_2 *) ctl->signature_page;
9292
}
9393

lib/setproctitle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void initproctitle (int argc, char **argv)
3333
for (i = 0; envp[i] != NULL; i++)
3434
continue;
3535

36-
environ = (char **) malloc(sizeof(char *) * (i + 1));
36+
environ = malloc(sizeof(char *) * (i + 1));
3737
if (environ == NULL)
3838
return;
3939

lib/strutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ char *strnchr(const char *s, size_t maxlen, int c)
247247
char *strndup(const char *s, size_t n)
248248
{
249249
size_t len = strnlen(s, n);
250-
char *new = (char *) malloc((len + 1) * sizeof(char));
250+
char *new = malloc((len + 1) * sizeof(char));
251251
if (!new)
252252
return NULL;
253253
new[len] = '\0';

libblkid/src/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
102102
DBG(CACHE, ul_debug("creating blkid cache (using %s)",
103103
filename ? filename : "default cache"));
104104

105-
if (!(cache = (blkid_cache) calloc(1, sizeof(struct blkid_struct_cache))))
105+
if (!(cache = calloc(1, sizeof(struct blkid_struct_cache))))
106106
return -BLKID_ERR_MEM;
107107

108108
INIT_LIST_HEAD(&cache->bic_devs);

libblkid/src/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct blkid_config *blkid_read_config(const char *filename)
120120
if (!filename)
121121
filename = BLKID_CONFIG_FILE;
122122

123-
conf = (struct blkid_config *) calloc(1, sizeof(*conf));
123+
conf = calloc(1, sizeof(*conf));
124124
if (!conf)
125125
return NULL;
126126
conf->uevent = -1;

libblkid/src/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ blkid_dev blkid_new_dev(void)
3434
{
3535
blkid_dev dev;
3636

37-
if (!(dev = (blkid_dev) calloc(1, sizeof(struct blkid_struct_dev))))
37+
if (!(dev = calloc(1, sizeof(struct blkid_struct_dev))))
3838
return NULL;
3939

4040
INIT_LIST_HEAD(&dev->bid_devs);

libblkid/src/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static blkid_tag blkid_new_tag(void)
2121
{
2222
blkid_tag tag;
2323

24-
if (!(tag = (blkid_tag) calloc(1, sizeof(struct blkid_struct_tag))))
24+
if (!(tag = calloc(1, sizeof(struct blkid_struct_tag))))
2525
return NULL;
2626

2727
INIT_LIST_HEAD(&tag->bit_tags);

login-utils/login.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ static void init_environ(struct login_context *cxt)
10391039

10401040
/* destroy environment unless user has requested preservation (-p) */
10411041
if (!cxt->keep_env) {
1042-
environ = (char **) xmalloc(sizeof(char *));
1042+
environ = xmalloc(sizeof(char *));
10431043
memset(environ, 0, sizeof(char *));
10441044
}
10451045

misc-utils/test_uuidd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static void create_nthreads(process_t *proc, size_t index)
161161
size_t i, ncreated = 0;
162162
int rc;
163163

164-
threads = (thread_t *) xcalloc(nthreads, sizeof(thread_t));
164+
threads = xcalloc(nthreads, sizeof(thread_t));
165165

166166
for (i = 0; i < nthreads; i++) {
167167
thread_t *th = &threads[i];
@@ -209,7 +209,7 @@ static void create_nprocesses(void)
209209
process_t *process;
210210
size_t i;
211211

212-
process = (process_t *) xcalloc(nprocesses, sizeof(process_t));
212+
process = xcalloc(nprocesses, sizeof(process_t));
213213

214214
for (i = 0; i < nprocesses; i++) {
215215
process_t *proc = &process[i];

sys-utils/swapon-common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static size_t ulct;
8686

8787
void add_label(const char *label)
8888
{
89-
llist = (const char **) xrealloc(llist, (++llct) * sizeof(char *));
89+
llist = xrealloc(llist, (++llct) * sizeof(char *));
9090
llist[llct - 1] = label;
9191
}
9292

@@ -102,7 +102,7 @@ size_t numof_labels(void)
102102

103103
void add_uuid(const char *uuid)
104104
{
105-
ulist = (const char **) xrealloc(ulist, (++ulct) * sizeof(char *));
105+
ulist = xrealloc(ulist, (++ulct) * sizeof(char *));
106106
ulist[ulct - 1] = uuid;
107107
}
108108

0 commit comments

Comments
 (0)