From: miko Date: Sat, 15 Sep 2018 12:15:32 +0000 (+0000) Subject: strsave() is hard-fail strdup() so simplify and rename to xstrdup(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=63a151f29f6025d1aba7630b7853699ed9656e09;p=openbsd strsave() is hard-fail strdup() so simplify and rename to xstrdup(). with help from martijn@. ok millert@ martijn@ --- diff --git a/bin/csh/error.c b/bin/csh/error.c index 723a6213485..6d8aa8321b2 100644 --- a/bin/csh/error.c +++ b/bin/csh/error.c @@ -1,4 +1,4 @@ -/* $OpenBSD: error.c,v 1.14 2018/09/08 01:28:39 miko Exp $ */ +/* $OpenBSD: error.c,v 1.15 2018/09/15 12:15:32 miko 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 aba5f06ca06..8cc67947a80 100644 --- a/bin/csh/extern.h +++ b/bin/csh/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.26 2017/07/22 09:37:21 anton Exp $ */ +/* $OpenBSD: extern.h,v 1.27 2018/09/15 12:15:32 miko Exp $ */ /* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */ /*- @@ -201,7 +201,7 @@ int prefix(Char *, Char *); Char **saveblk(Char **); Char *strip(Char *); Char *quote(Char *); -char *strsave(char *); +char *xstrdup(const char *); char *strspl(char *, char *); void udvar(Char *); diff --git a/bin/csh/misc.c b/bin/csh/misc.c index 5fc9e8d815b..f6030765c92 100644 --- a/bin/csh/misc.c +++ b/bin/csh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.20 2017/06/20 16:44:06 anton Exp $ */ +/* $OpenBSD: misc.c,v 1.21 2018/09/15 12:15:32 miko Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/03/21 09:03:09 cgd Exp $ */ /*- @@ -34,6 +34,7 @@ #include #include #include +#include #include "csh.h" #include "extern.h" @@ -53,18 +54,16 @@ any(char *s, int c) } char * -strsave(char *s) +xstrdup(const char *s) { - char *n; - char *p; + char *n; if (s == NULL) s = ""; - for (p = s; *p++;) - continue; - n = p = xreallocarray(NULL, (p - s), sizeof(char)); - while ((*p++ = *s++) != '\0') - continue; + if ((n = strdup(s)) == NULL) { + child++; + stderror(ERR_NOMEM); + } return (n); } diff --git a/bin/csh/str.c b/bin/csh/str.c index edf45e31188..2355bab92bb 100644 --- a/bin/csh/str.c +++ b/bin/csh/str.c @@ -1,4 +1,4 @@ -/* $OpenBSD: str.c,v 1.19 2015/10/26 16:31:09 naddy Exp $ */ +/* $OpenBSD: str.c,v 1.20 2018/09/15 12:15:32 miko 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); }