diff options
author | joerg <joerg> | 2008-08-02 20:33:50 +0000 |
---|---|---|
committer | joerg <joerg> | 2008-08-02 20:33:50 +0000 |
commit | 7be93b44a0d2e33aa0dd07de5f5b673bf95b27c8 (patch) | |
tree | 8901b5966bac844405a560018181d94cc4eccd35 /pkgtools/pkg_install/files/lib/path.c | |
parent | f3a58140319f67643ea733850de213b695037b07 (diff) | |
download | pkgsrc-7be93b44a0d2e33aa0dd07de5f5b673bf95b27c8.tar.gz |
Most memory allocation failures were fatal already and the majority of
the rest lacked an explicit check. Add the usual x* wrappers around
malloc and friends that explicitly terminate on error and use them in
all but Dewey.
Diffstat (limited to 'pkgtools/pkg_install/files/lib/path.c')
-rw-r--r-- | pkgtools/pkg_install/files/lib/path.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/pkgtools/pkg_install/files/lib/path.c b/pkgtools/pkg_install/files/lib/path.c index 5ef484ebffd..fac576ca850 100644 --- a/pkgtools/pkg_install/files/lib/path.c +++ b/pkgtools/pkg_install/files/lib/path.c @@ -1,4 +1,4 @@ -/* $NetBSD: path.c,v 1.6 2004/12/29 12:16:56 agc Exp $ */ +/* $NetBSD: path.c,v 1.6.28.1 2008/08/02 20:33:50 joerg Exp $ */ /*- * Copyright (c)2002 YAMAMOTO Takashi, @@ -34,7 +34,7 @@ #include <sys/cdefs.h> #endif #ifndef lint -__RCSID("$NetBSD: path.c,v 1.6 2004/12/29 12:16:56 agc Exp $"); +__RCSID("$NetBSD: path.c,v 1.6.28.1 2008/08/02 20:33:50 joerg Exp $"); #endif #if HAVE_ERR_H @@ -113,29 +113,18 @@ path_new_entry(const char *cp, size_t len) { struct path *new; - new = malloc(sizeof(*new)); - if (new == NULL) - err(EXIT_FAILURE, "path_create"); + new = xmalloc(sizeof(*new)); if (!IS_FULLPATH(cp) && !IS_URL(cp)) { /* this is a relative path */ - size_t total; char cwd[MaxPathSize]; - size_t cwdlen; if (getcwd(cwd, sizeof(cwd)) == NULL) err(EXIT_FAILURE, "getcwd"); - cwdlen = strlen(cwd); - total = cwdlen + 1 + len + 1; - new->pl_path = malloc(total); - if (new->pl_path == NULL) - err(EXIT_FAILURE, "path_create"); - snprintf(new->pl_path, total, "%s/%*.*s", cwd, (int)len, (int)len, cp); + new->pl_path = xasprintf("%s/%*.*s", cwd, (int)len, (int)len, cp); } else { - new->pl_path = malloc(len + 1); - if (new->pl_path == NULL) - err(EXIT_FAILURE, "path_create"); + new->pl_path = xmalloc(len + 1); memcpy(new->pl_path, cp, len); new->pl_path[len] = '\0'; } @@ -183,9 +172,7 @@ path_setenv(const char *envname) TAILQ_FOREACH(p, &PkgPath, pl_entry) len += strlen(p->pl_path) + 1; - env = malloc(len); - if (env == NULL) - err(EXIT_FAILURE, "path_setenv"); + env = xmalloc(len); env0 = env; envend = env + len; |