diff options
author | 2014-07-05 05:05:51 +0000 | |
---|---|---|
committer | 2014-07-05 05:05:51 +0000 | |
commit | bbadc118cf51728f73417606a6e4fb2a206cdfab (patch) | |
tree | a725df64bafd63efde93cd8360f6353ee873d5cf | |
parent | Cleanup regarding -offset and -width: (diff) | |
download | wireguard-openbsd-bbadc118cf51728f73417606a6e4fb2a206cdfab.tar.xz wireguard-openbsd-bbadc118cf51728f73417606a6e4fb2a206cdfab.zip |
Use void* in malloc/realloc/calloc wrappers
-rw-r--r-- | usr.bin/rdist/child.c | 4 | ||||
-rw-r--r-- | usr.bin/rdist/client.c | 6 | ||||
-rw-r--r-- | usr.bin/rdist/common.c | 35 | ||||
-rw-r--r-- | usr.bin/rdist/defs.h | 8 | ||||
-rw-r--r-- | usr.bin/rdist/docmd.c | 9 | ||||
-rw-r--r-- | usr.bin/rdist/message.c | 4 | ||||
-rw-r--r-- | usr.bin/rdist/rdist.c | 4 |
7 files changed, 33 insertions, 37 deletions
diff --git a/usr.bin/rdist/child.c b/usr.bin/rdist/child.c index ec2af8aa43e..26fb18dd894 100644 --- a/usr.bin/rdist/child.c +++ b/usr.bin/rdist/child.c @@ -1,4 +1,4 @@ -/* $OpenBSD: child.c,v 1.17 2014/07/04 21:50:13 guenther Exp $ */ +/* $OpenBSD: child.c,v 1.18 2014/07/05 05:05:51 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -138,7 +138,7 @@ copychild(CHILD *child) { CHILD *newc; - newc = (CHILD *) xmalloc(sizeof(CHILD)); + newc = xmalloc(sizeof *newc); newc->c_name = xstrdup(child->c_name); newc->c_readfd = child->c_readfd; diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c index 8189cb3fa48..17d66472f33 100644 --- a/usr.bin/rdist/client.c +++ b/usr.bin/rdist/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.26 2013/08/18 16:32:24 guenther Exp $ */ +/* $OpenBSD: client.c,v 1.27 2014/07/05 05:05:51 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -204,7 +204,7 @@ addcmdspecialfile(char *starget, char *rname, int destdir) } if (isokay) { - new = (struct namelist *) xmalloc(sizeof(struct namelist)); + new = xmalloc(sizeof *new); new->n_name = xstrdup(rfile); new->n_regex = NULL; new->n_next = updfilelist; @@ -323,7 +323,7 @@ linkinfo(struct stat *statp) return(lp); } - lp = (struct linkbuf *) xmalloc(sizeof(*lp)); + lp = xmalloc(sizeof(*lp)); lp->nextp = ihead; ihead = lp; lp->inum = statp->st_ino; diff --git a/usr.bin/rdist/common.c b/usr.bin/rdist/common.c index 0298754ea2d..5fb15702cef 100644 --- a/usr.bin/rdist/common.c +++ b/usr.bin/rdist/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.26 2011/04/24 02:23:57 deraadt Exp $ */ +/* $OpenBSD: common.c,v 1.27 2014/07/05 05:05:51 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -831,44 +831,44 @@ runcommand(char *cmd) /* * Malloc with error checking */ -char * +void * xmalloc(size_t amt) { - char *ptr; + void *ptr; - if ((ptr = (char *)malloc(amt)) == NULL) + if ((ptr = malloc(amt)) == NULL) fatalerr("Cannot malloc %zu bytes of memory.", amt); - return(ptr); + return (ptr); } /* * realloc with error checking */ -char * -xrealloc(char *baseptr, size_t amt) +void * +xrealloc(void *baseptr, size_t amt) { - char *new; + void *new; - if ((new = (char *)realloc(baseptr, amt)) == NULL) + if ((new = realloc(baseptr, amt)) == NULL) fatalerr("Cannot realloc %zu bytes of memory.", amt); - return(new); + return (new); } /* * calloc with error checking */ -char * +void * xcalloc(size_t num, size_t esize) { - char *ptr; + void *ptr; - if ((ptr = (char *)calloc(num, esize)) == NULL) + if ((ptr = calloc(num, esize)) == NULL) fatalerr("Cannot calloc %zu * %zu = %zu bytes of memory.", num, esize, num * esize); - return(ptr); + return (ptr); } /* @@ -878,12 +878,9 @@ char * xstrdup(const char *str) { size_t len = strlen(str) + 1; - char *nstr = (char *) malloc(len); - - if (nstr == NULL) - fatalerr("Cannot malloc %zu bytes of memory.", len); + char *nstr = xmalloc(len); - return(memcpy(nstr, str, len)); + return (memcpy(nstr, str, len)); } /* diff --git a/usr.bin/rdist/defs.h b/usr.bin/rdist/defs.h index d3d62bfac8d..c64c2366638 100644 --- a/usr.bin/rdist/defs.h +++ b/usr.bin/rdist/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.19 2013/12/21 06:29:17 guenther Exp $ */ +/* $OpenBSD: defs.h,v 1.20 2014/07/05 05:05:51 guenther Exp $ */ #ifndef __DEFS_H__ #define __DEFS_H__ @@ -380,9 +380,9 @@ int becomeroot(void); int setfiletime(char *, time_t, time_t); char *getversion(void); void runcommand(char *); -char *xmalloc(size_t); -char *xrealloc(char *, size_t); -char *xcalloc(size_t, size_t); +void *xmalloc(size_t); +void *xrealloc(void *, size_t); +void *xcalloc(size_t, size_t); char *xstrdup(const char *); char *xbasename(char *); char *searchpath(char *); diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c index ad0645c2b9f..955110b22bd 100644 --- a/usr.bin/rdist/docmd.c +++ b/usr.bin/rdist/docmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: docmd.c,v 1.25 2012/11/12 01:14:41 guenther Exp $ */ +/* $OpenBSD: docmd.c,v 1.26 2014/07/05 05:05:51 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -724,7 +724,7 @@ cmptime(char *name, struct subcmd *sbcmds, char **env) message(MT_CHANGE, "special \"%s\"", buf); if (*env) { size_t len = strlen(*env) + strlen(name) + 2; - *env = (char *) xrealloc(*env, len); + *env = xrealloc(*env, len); (void) strlcat(*env, name, len); (void) strlcat(*env, ":", len); } @@ -767,7 +767,7 @@ dodcolon(struct cmd *cmd, char **filev) env = NULL; for (sc = sbcmds; sc != NULL; sc = sc->sc_next) { if (sc->sc_type == CMDSPECIAL) { - env = (char *) xmalloc(sizeof(E_FILES) + 3); + env = xmalloc(sizeof(E_FILES) + 3); (void) snprintf(env, sizeof(E_FILES) + 3, "%s='", E_FILES); break; @@ -843,8 +843,7 @@ except(char *file) /* allocate and compile n_regex as needed */ if (nl->n_regex == NULL) { - nl->n_regex = (regex_t *) - xmalloc(sizeof(regex_t)); + nl->n_regex = xmalloc(sizeof(regex_t)); ecode = regcomp(nl->n_regex, nl->n_name, REG_NOSUB); } diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c index da15ba81fcb..b0c88e16d89 100644 --- a/usr.bin/rdist/message.c +++ b/usr.bin/rdist/message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.19 2013/12/21 06:29:17 guenther Exp $ */ +/* $OpenBSD: message.c,v 1.20 2014/07/05 05:05:51 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -448,7 +448,7 @@ msgsendnotify(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) if ((cp = getenv("TMPDIR")) == NULL || *cp == '\0') cp = _PATH_TMP; len = strlen(cp) + 1 + sizeof(_RDIST_TMP); - tempfile = (char *) xmalloc(len); + tempfile = xmalloc(len); (void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP); msgfac->mf_filename = tempfile; diff --git a/usr.bin/rdist/rdist.c b/usr.bin/rdist/rdist.c index 96fc5aa2f95..c6e0ba5439d 100644 --- a/usr.bin/rdist/rdist.c +++ b/usr.bin/rdist/rdist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdist.c,v 1.21 2011/04/21 02:44:15 krw Exp $ */ +/* $OpenBSD: rdist.c,v 1.22 2014/07/05 05:05:51 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -66,7 +66,7 @@ addhostlist(char *name, struct namelist **hostlist) if (!name || !hostlist) return; - new = (struct namelist *) xmalloc(sizeof(struct namelist)); + new = xmalloc(sizeof *new); new->n_name = xstrdup(name); new->n_regex = NULL; new->n_next = NULL; |