From: millert Date: Tue, 18 Sep 2018 17:48:22 +0000 (+0000) Subject: Restore the xmalloc(), xcalloc(), xreallocarray() and xstrdup() changes. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=44cfad27cf73226af86c1bc021832606ebc495a0;p=openbsd Restore the xmalloc(), xcalloc(), xreallocarray() and xstrdup() changes. OK deraadt@ --- diff --git a/bin/csh/alloc.c b/bin/csh/alloc.c index 49af41d9543..7720ddb9536 100644 --- a/bin/csh/alloc.c +++ b/bin/csh/alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc.c,v 1.19 2018/09/18 06:56:09 deraadt Exp $ */ +/* $OpenBSD: alloc.c,v 1.20 2018/09/18 17:48:22 millert Exp $ */ /* $NetBSD: alloc.c,v 1.6 1995/03/21 09:02:23 cgd Exp $ */ /*- @@ -34,12 +34,13 @@ #include #include #include +#include #include "csh.h" #include "extern.h" void * -Malloc(size_t n) +xmalloc(size_t n) { void *ptr; @@ -51,7 +52,7 @@ Malloc(size_t n) } void * -Reallocarray(void * p, size_t c, size_t n) +xreallocarray(void * p, size_t c, size_t n) { void *ptr; @@ -63,7 +64,7 @@ Reallocarray(void * p, size_t c, size_t n) } void * -Calloc(size_t s, size_t n) +xcalloc(size_t s, size_t n) { void *ptr; @@ -74,3 +75,17 @@ Calloc(size_t s, size_t n) return (ptr); } + +char * +xstrdup(const char *s) +{ + char *n; + + if (s == NULL) + s = ""; + if ((n = strdup(s)) == NULL) { + child++; + stderror(ERR_NOMEM); + } + return (n); +} diff --git a/bin/csh/csh.h b/bin/csh/csh.h index fe324b36807..aa88f3ad1f9 100644 --- a/bin/csh/csh.h +++ b/bin/csh/csh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: csh.h,v 1.32 2018/09/18 06:56:09 deraadt Exp $ */ +/* $OpenBSD: csh.h,v 1.33 2018/09/18 17:48:22 millert Exp $ */ /* $NetBSD: csh.h,v 1.9 1995/03/21 09:02:40 cgd Exp $ */ /*- @@ -69,10 +69,6 @@ typedef void *ioctl_t; /* Third arg of ioctl */ #include "char.h" #include "error.h" -#define xmalloc(i) Malloc(i) -#define xreallocarray(p, i, j) Reallocarray(p, i, j) -#define xcalloc(n, s) Calloc(n, s) - #include FILE *cshin, *cshout, *csherr; diff --git a/bin/csh/error.c b/bin/csh/error.c index 069d1b8a626..9aa4054761f 100644 --- a/bin/csh/error.c +++ b/bin/csh/error.c @@ -1,4 +1,4 @@ -/* $OpenBSD: error.c,v 1.16 2018/09/18 06:56:09 deraadt Exp $ */ +/* $OpenBSD: error.c,v 1.17 2018/09/18 17:48:22 millert Exp $ */ /* $NetBSD: err.c,v 1.6 1995/03/21 09:02:47 cgd Exp $ */ /*- @@ -289,7 +289,7 @@ seterror(int id, ...) vsnprintf(berr, sizeof(berr), errorlist[id], va); va_end(va); - seterr = strsave(berr); + seterr = xstrdup(berr); } } diff --git a/bin/csh/extern.h b/bin/csh/extern.h index e8e4fe6fb28..cdbe62bbbb2 100644 --- a/bin/csh/extern.h +++ b/bin/csh/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.30 2018/09/18 06:56:09 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.31 2018/09/18 17:48:22 millert Exp $ */ /* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */ /*- @@ -201,7 +201,6 @@ int prefix(Char *, Char *); Char **saveblk(Char **); Char *strip(Char *); Char *quote(Char *); -char *strsave(char *); char *strspl(char *, char *); void udvar(Char *); @@ -281,9 +280,10 @@ void psecs(long); /* * alloc.c */ -void * Malloc(size_t); -void * Reallocarray(void *, size_t, size_t); -void * Calloc(size_t, size_t); +void *xmalloc(size_t); +void *xreallocarray(void *, size_t, size_t); +void *xcalloc(size_t, size_t); +char *xstrdup(const char *); /* * str.c: diff --git a/bin/csh/misc.c b/bin/csh/misc.c index 08f456de03d..c11765a2a31 100644 --- a/bin/csh/misc.c +++ b/bin/csh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.23 2018/09/18 06:56:09 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.24 2018/09/18 17:48:22 millert Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/03/21 09:03:09 cgd Exp $ */ /*- @@ -52,22 +52,6 @@ any(char *s, int c) return (0); } -char * -strsave(char *s) -{ - char *n; - char *p; - - if (s == NULL) - s = ""; - for (p = s; *p++;) - continue; - n = p = xreallocarray(NULL, (p - s), sizeof(char)); - while ((*p++ = *s++) != '\0') - continue; - return (n); -} - Char ** blkend(Char **up) { diff --git a/bin/csh/str.c b/bin/csh/str.c index 6efbfe29d7f..108639c3c69 100644 --- a/bin/csh/str.c +++ b/bin/csh/str.c @@ -1,4 +1,4 @@ -/* $OpenBSD: str.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */ +/* $OpenBSD: str.c,v 1.22 2018/09/18 17:48:22 millert Exp $ */ /* $NetBSD: str.c,v 1.6 1995/03/21 09:03:24 cgd Exp $ */ /*- @@ -77,7 +77,7 @@ short2blk(Char **src) sdst = dst = xreallocarray(NULL, n + 1, sizeof(char *)); for (; *src != NULL; src++) - *dst++ = strsave(short2str(*src)); + *dst++ = xstrdup(short2str(*src)); *dst = NULL; return (sdst); }