Skip to content

Commit

Permalink
<stdlib.h> is included, so do not need to cast result from
Browse files Browse the repository at this point in the history
malloc, calloc, realloc*
ok krw millert
  • Loading branch information
deraadt committed Aug 20, 2015
1 parent 285f54c commit 5ae94ef
Show file tree
Hide file tree
Showing 39 changed files with 130 additions and 153 deletions.
4 changes: 2 additions & 2 deletions sbin/atactl/atactl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: atactl.c,v 1.45 2015/01/16 06:39:56 deraadt Exp $ */
/* $OpenBSD: atactl.c,v 1.46 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: atactl.c,v 1.4 1999/02/24 18:49:14 jwise Exp $ */

/*-
Expand Down Expand Up @@ -1461,7 +1461,7 @@ device_smart_readlog(int argc, char *argv[])
* the latest one.
*/
nsect = nerr / 5 + (nerr % 5 != 0 ? 1 : 0);
if ((newbuf = (u_int8_t *)calloc(nsect, DEV_BSIZE)) == NULL)
if ((newbuf = calloc(nsect, DEV_BSIZE)) == NULL)
err(1, "calloc()");
memset(&req, 0, sizeof(req));
req.flags = ATACMD_READ;
Expand Down
4 changes: 2 additions & 2 deletions sbin/disklabel/disklabel.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: disklabel.c,v 1.203 2015/08/15 17:16:10 krw Exp $ */
/* $OpenBSD: disklabel.c,v 1.204 2015/08/20 22:02:20 deraadt Exp $ */

/*
* Copyright (c) 1987, 1993
Expand Down Expand Up @@ -573,7 +573,7 @@ makebootarea(char *boot, struct disklabel *dp)
if (bootsize > 0) {
/* XXX assume d_secsize is a power of two */
bootsize = (bootsize + dp->d_secsize-1) & ~(dp->d_secsize-1);
bootbuf = (char *)malloc((size_t)bootsize);
bootbuf = malloc((size_t)bootsize);
if (bootbuf == NULL)
err(4, "%s", xxboot);
if (read(b, bootbuf, bootsize) < 0) {
Expand Down
10 changes: 4 additions & 6 deletions sbin/dump/itime.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: itime.c,v 1.21 2015/05/23 05:17:20 guenther Exp $ */
/* $OpenBSD: itime.c,v 1.22 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: itime.c,v 1.4 1997/04/15 01:09:50 lukem Exp $ */

/*-
Expand Down Expand Up @@ -96,7 +96,7 @@ readdumptimes(FILE *df)
struct dumptime *dtwalk;

for (;;) {
dtwalk = (struct dumptime *)calloc(1, sizeof(struct dumptime));
dtwalk = calloc(1, sizeof(struct dumptime));
if (getrecord(df, &(dtwalk->dt_value)) < 0) {
free(dtwalk);
break;
Expand All @@ -111,8 +111,7 @@ readdumptimes(FILE *df)
* arrayify the list, leaving enough room for the additional
* record that we may have to add to the ddate structure
*/
ddatev = (struct dumpdates **)
calloc((unsigned) (nddates + 1), sizeof(struct dumpdates *));
ddatev = calloc((unsigned) (nddates + 1), sizeof(struct dumpdates *));
dtwalk = dthead;
for (i = nddates - 1; i >= 0; i--, dtwalk = dtwalk->dt_next)
ddatev[i] = &dtwalk->dt_value;
Expand Down Expand Up @@ -190,8 +189,7 @@ putdumptime(void)
* construct the new upper bound;
* Enough room has been allocated.
*/
dtwalk = ddatev[nddates] =
(struct dumpdates *)calloc(1, sizeof(struct dumpdates));
dtwalk = ddatev[nddates] = calloc(1, sizeof(struct dumpdates));
nddates += 1;
found:
(void) strlcpy(dtwalk->dd_name, fname, sizeof(dtwalk->dd_name));
Expand Down
8 changes: 4 additions & 4 deletions sbin/dump/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.56 2015/05/23 05:17:20 guenther Exp $ */
/* $OpenBSD: main.c,v 1.57 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */

/*-
Expand Down Expand Up @@ -450,9 +450,9 @@ main(int argc, char *argv[])
#endif
maxino = sblock->fs_ipg * sblock->fs_ncg;
mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE);
usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char));
dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
usedinomap = calloc((unsigned) mapsize, sizeof(char));
dumpdirmap = calloc((unsigned) mapsize, sizeof(char));
dumpinomap = calloc((unsigned) mapsize, sizeof(char));
tapesize = 3 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);

nonodump = spcl.c_level < honorlevel;
Expand Down
6 changes: 3 additions & 3 deletions sbin/dump/optr.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: optr.c,v 1.37 2015/05/23 05:17:20 guenther Exp $ */
/* $OpenBSD: optr.c,v 1.38 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: optr.c,v 1.11 1997/05/27 08:34:36 mrg Exp $ */

/*-
Expand Down Expand Up @@ -274,7 +274,7 @@ allocfsent(struct fstab *fs)
{
struct fstab *new;

new = (struct fstab *)malloc(sizeof(*fs));
new = malloc(sizeof(*fs));
if (new == NULL ||
(new->fs_file = strdup(fs->fs_file)) == NULL ||
(new->fs_type = strdup(fs->fs_type)) == NULL ||
Expand Down Expand Up @@ -312,7 +312,7 @@ getfstab(void)
strcmp(fs->fs_type, FSTAB_RQ))
continue;
fs = allocfsent(fs);
if ((pf = (struct pfstab *)malloc(sizeof(*pf))) == NULL)
if ((pf = malloc(sizeof(*pf))) == NULL)
quit("%s\n", strerror(errno));
pf->pf_fstab = fs;
pf->pf_next = table;
Expand Down
5 changes: 2 additions & 3 deletions sbin/dump/tape.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: tape.c,v 1.42 2015/01/20 18:22:20 deraadt Exp $ */
/* $OpenBSD: tape.c,v 1.43 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: tape.c,v 1.11 1997/06/05 11:13:26 lukem Exp $ */

/*-
Expand Down Expand Up @@ -138,8 +138,7 @@ alloctape(void)
* Align tape buffer on page boundary to speed up tape write().
*/
for (i = 0; i <= SLAVES; i++) {
buf = (char *)
malloc((unsigned)(reqsiz + writesize + pgoff + TP_BSIZE));
buf = malloc((unsigned)(reqsiz + writesize + pgoff + TP_BSIZE));
if (buf == NULL)
return(0);
slaves[i].tblock = (char (*)[TP_BSIZE])
Expand Down
6 changes: 3 additions & 3 deletions sbin/fsck_ext2fs/pass1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: pass1.c,v 1.15 2015/01/16 06:39:57 deraadt Exp $ */
/* $OpenBSD: pass1.c,v 1.16 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: pass1.c,v 1.9 2000/01/31 11:40:12 bouyer Exp $ */

/*
Expand Down Expand Up @@ -239,7 +239,7 @@ checkinode(ino_t inumber, struct inodesc *idesc)
n_files++;
lncntp[inumber] = letoh16(dp->e2di_nlink);
if (dp->e2di_nlink == 0) {
zlnp = (struct zlncnt *)malloc(sizeof *zlnp);
zlnp = malloc(sizeof *zlnp);
if (zlnp == NULL) {
pfatal("LINK COUNT TABLE OVERFLOW");
if (reply("CONTINUE") == 0)
Expand Down Expand Up @@ -326,7 +326,7 @@ pass1check(struct inodesc *idesc)
errexit("%s\n", "");
return (STOP);
}
new = (struct dups *)malloc(sizeof(struct dups));
new = malloc(sizeof(struct dups));
if (new == NULL) {
pfatal("DUP TABLE OVERFLOW.");
if (reply("CONTINUE") == 0)
Expand Down
10 changes: 4 additions & 6 deletions sbin/fsck_ext2fs/setup.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: setup.c,v 1.25 2015/01/16 06:39:57 deraadt Exp $ */
/* $OpenBSD: setup.c,v 1.26 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: setup.c,v 1.1 1997/06/11 11:22:01 bouyer Exp $ */

/*
Expand Down Expand Up @@ -218,7 +218,7 @@ setup(char *dev)
(unsigned)(maxino + 1));
goto badsblabel;
}
lncntp = (int16_t *)calloc((unsigned)(maxino + 1), sizeof(int16_t));
lncntp = calloc((unsigned)(maxino + 1), sizeof(int16_t));
if (lncntp == NULL) {
printf("cannot alloc %u bytes for lncntp\n",
(unsigned)((maxino + 1) * sizeof(int16_t)));
Expand All @@ -229,10 +229,8 @@ setup(char *dev)
}
inplast = 0;
listmax = numdirs + 10;
inpsort = (struct inoinfo **)calloc((unsigned)listmax,
sizeof(struct inoinfo *));
inphead = (struct inoinfo **)calloc((unsigned)numdirs,
sizeof(struct inoinfo *));
inpsort = calloc((unsigned)listmax, sizeof(struct inoinfo *));
inphead = calloc((unsigned)numdirs, sizeof(struct inoinfo *));
if (inpsort == NULL || inphead == NULL) {
printf("cannot alloc %u bytes for inphead\n",
(unsigned)(numdirs * sizeof(struct inoinfo *)));
Expand Down
4 changes: 2 additions & 2 deletions sbin/fsck_ext2fs/utilities.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: utilities.c,v 1.24 2015/01/16 06:39:57 deraadt Exp $ */
/* $OpenBSD: utilities.c,v 1.25 2015/08/20 22:02:20 deraadt Exp $ */
/* $NetBSD: utilities.c,v 1.6 2001/02/04 21:19:34 christos Exp $ */

/*
Expand Down Expand Up @@ -127,7 +127,7 @@ bufinit(void)
if (bufcnt < MINBUFS)
bufcnt = MINBUFS;
for (i = 0; i < bufcnt; i++) {
bp = (struct bufarea *)malloc(sizeof(struct bufarea));
bp = malloc(sizeof(struct bufarea));
bufp = malloc((unsigned int)sblock.e2fs_bsize);
if (bp == NULL || bufp == NULL) {
free(bp);
Expand Down
6 changes: 3 additions & 3 deletions sbin/fsck_msdos/dir.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: dir.c,v 1.28 2015/01/16 06:39:58 deraadt Exp $ */
/* $OpenBSD: dir.c,v 1.29 2015/08/20 22:02:21 deraadt Exp $ */
/* $NetBSD: dir.c,v 1.11 1997/10/17 11:19:35 ws Exp $ */

/*
Expand Down Expand Up @@ -103,7 +103,7 @@ newDosDirEntry(void)
struct dosDirEntry *de;

if (!(de = freede)) {
if (!(de = (struct dosDirEntry *)malloc(sizeof *de)))
if (!(de = malloc(sizeof *de)))
return (0);
} else
freede = de->next;
Expand All @@ -128,7 +128,7 @@ newDirTodo(void)
struct dirTodoNode *dt;

if (!(dt = freedt)) {
if (!(dt = (struct dirTodoNode *)malloc(sizeof *dt)))
if (!(dt = malloc(sizeof *dt)))
return (0);
} else
freedt = dt->next;
Expand Down
6 changes: 3 additions & 3 deletions sbin/growfs/growfs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: growfs.c,v 1.39 2015/04/18 18:28:37 deraadt Exp $ */
/* $OpenBSD: growfs.c,v 1.40 2015/08/20 22:02:21 deraadt Exp $ */
/*
* Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz
* Copyright (c) 1980, 1989, 1993 The Regents of the University of California.
Expand Down Expand Up @@ -1240,7 +1240,7 @@ updcsloc(time_t utime, int fsi, int fso, unsigned int Nflag)
/*
* Allocate the space for the array of blocks to be relocated.
*/
bp = (struct gfs_bpp *)calloc(((dupper-odupper) / sblock.fs_frag + 2),
bp = calloc(((dupper-odupper) / sblock.fs_frag + 2),
sizeof(struct gfs_bpp));
if (bp == NULL)
errx(1, "calloc failed");
Expand Down Expand Up @@ -2211,7 +2211,7 @@ get_disklabel(int fd)

DBG_ENTER;

lab = (struct disklabel *)malloc(sizeof(struct disklabel));
lab = malloc(sizeof(struct disklabel));
if (!lab)
errx(1, "malloc failed");
if (ioctl(fd, DIOCGDINFO, (char *)lab) != 0)
Expand Down
5 changes: 2 additions & 3 deletions sbin/init/init.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: init.c,v 1.53 2015/07/14 19:14:05 millert Exp $ */
/* $OpenBSD: init.c,v 1.54 2015/08/20 22:02:21 deraadt Exp $ */
/* $NetBSD: init.c,v 1.22 1996/05/15 23:29:33 jtc Exp $ */

/*-
Expand Down Expand Up @@ -834,8 +834,7 @@ char **
construct_argv(char *command)
{
int argc = 0;
char **argv = (char **) calloc((strlen(command) + 1) / 2 + 1,
sizeof (char *));
char **argv = calloc((strlen(command) + 1) / 2 + 1, sizeof (char *));
static const char separators[] = " \t";

if (argv == NULL)
Expand Down
17 changes: 7 additions & 10 deletions sbin/isakmpd/conf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: conf.c,v 1.103 2013/11/22 04:12:47 deraadt Exp $ */
/* $OpenBSD: conf.c,v 1.104 2015/08/20 22:02:21 deraadt Exp $ */
/* $EOM: conf.c,v 1.48 2000/12/04 02:04:29 angelos Exp $ */

/*
Expand Down Expand Up @@ -978,7 +978,7 @@ conf_report(void)
char *current_section = (char *)0;
struct dumper *dumper, *dnode;

dumper = dnode = (struct dumper *)calloc(1, sizeof *dumper);
dumper = dnode = calloc(1, sizeof *dumper);
if (!dumper)
goto mem_fail;

Expand All @@ -995,17 +995,15 @@ conf_report(void)
if (asprintf(&dnode->s, "[%s]",
current_section) == -1)
goto mem_fail;
dnode->next = (struct dumper *)
calloc(1,
sizeof(struct dumper));
dnode->next = calloc(1,
sizeof(struct dumper));
dnode = dnode->next;
if (!dnode)
goto mem_fail;

dnode->s = "";
dnode->next = (struct dumper *)
calloc(1,
sizeof(struct dumper));
dnode->next = calloc(1,
sizeof(struct dumper));
dnode = dnode->next;
if (!dnode)
goto mem_fail;
Expand All @@ -1014,8 +1012,7 @@ conf_report(void)
}
dnode->s = cb->tag;
dnode->v = cb->value;
dnode->next = (struct dumper *)
calloc(1, sizeof(struct dumper));
dnode->next = calloc(1, sizeof(struct dumper));
dnode = dnode->next;
if (!dnode)
goto mem_fail;
Expand Down
4 changes: 2 additions & 2 deletions sbin/isakmpd/dnssec.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: dnssec.c,v 1.24 2015/01/16 06:39:58 deraadt Exp $ */
/* $OpenBSD: dnssec.c,v 1.25 2015/08/20 22:02:21 deraadt Exp $ */

/*
* Copyright (c) 2001 Håkan Olsson. All rights reserved.
Expand Down Expand Up @@ -215,7 +215,7 @@ dns_get_key(int type, struct message *msg, int *keylen)
continue;
}
/* This key seems to fit our requirements... */
key_rr.data = (char *)malloc(key_rr.datalen);
key_rr.data = malloc(key_rr.datalen);
if (!key_rr.data) {
log_error("dns_get_key: malloc (%d) failed",
key_rr.datalen);
Expand Down
6 changes: 3 additions & 3 deletions sbin/isakmpd/ike_phase_1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: ike_phase_1.c,v 1.74 2015/02/15 01:56:42 tedu Exp $ */
/* $OpenBSD: ike_phase_1.c,v 1.75 2015/08/20 22:02:21 deraadt Exp $ */
/* $EOM: ike_phase_1.c,v 1.31 2000/12/11 23:47:56 niklas Exp $ */

/*
Expand Down Expand Up @@ -284,11 +284,11 @@ ike_phase_1_initiator_send_SA(struct message *msg)
proto->xf_cnt = conf->cnt;
TAILQ_INIT(&proto->xfs);
for (i = 0; i < proto->xf_cnt; i++) {
pa = (struct proto_attr *)calloc(1, sizeof *pa);
pa = calloc(1, sizeof *pa);
if (!pa)
goto bail_out;
pa->len = transform_len[i];
pa->attrs = (u_int8_t *)malloc(pa->len);
pa->attrs = malloc(pa->len);
if (!pa->attrs) {
free(pa);
goto bail_out;
Expand Down
7 changes: 3 additions & 4 deletions sbin/isakmpd/ike_quick_mode.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: ike_quick_mode.c,v 1.108 2014/10/09 02:38:56 deraadt Exp $ */
/* $OpenBSD: ike_quick_mode.c,v 1.109 2015/08/20 22:02:21 deraadt Exp $ */
/* $EOM: ike_quick_mode.c,v 1.139 2001/01/26 10:43:17 niklas Exp $ */

/*
Expand Down Expand Up @@ -756,16 +756,15 @@ initiator_send_HASH_SA_NONCE(struct message *msg)
proto->xf_cnt = transform_cnt[prop_no];
TAILQ_INIT(&proto->xfs);
for (xf_no = 0; xf_no < proto->xf_cnt; xf_no++) {
pa = (struct proto_attr *)calloc(1,
sizeof *pa);
pa = calloc(1, sizeof *pa);
if (!pa) {
if (proto->data)
free(proto->data);
free(proto);
goto bail_out;
}
pa->len = transform_len[prop_no][xf_no];
pa->attrs = (u_int8_t *)malloc(pa->len);
pa->attrs = malloc(pa->len);
if (!pa->attrs) {
if (proto->data)
free(proto->data);
Expand Down
Loading

0 comments on commit 5ae94ef

Please sign in to comment.