Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
which: use xmalloc
Baptiste Daroussin committed 2 months ago
commit 496b9e517963a96007a6f428b1c558d32f259a5d
parent 3023e7a
1 file changed +2 -10
modified src/which.c
@@ -146,13 +146,9 @@ exec_which(int argc, char **argv)
				savedpath=p;
				for (;;) {
					res = get_match(&match, &p, argv[0]);
-
					if (res == (EXIT_FAILURE)) {
+
					if (res == EXIT_FAILURE) {
						printf("%s was not found in PATH, falling back to non-search behaviour\n", argv[0]);
						search = false;
-
					} else if (res == (EXIT_FAILURE)) {
-
						retcode = EXIT_FAILURE;
-
						free(savedpath);
-
						goto cleanup;
					} else {
						pkg_absolutepath(match, pathabs, sizeof(pathabs), false);
						/* ensure not not append twice an entry if PATH is messy */
@@ -251,11 +247,7 @@ get_match(char **pathabs, char **path, char *filename)
		    filename) >= (int)sizeof(candidate))
			continue;
		if (is_there(candidate)) {
-
			len = strlen(candidate) + 1;
-
			*pathabs = malloc(len);
-
			if (*pathabs == NULL)
-
				return (EXIT_FAILURE);
-
			strlcpy(*pathabs, candidate, len);
+
			*pathabs = xstrdup(candidate);
			return (EXIT_SUCCESS);
		}
	}