aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJarno Mäkipää <jmakip87@gmail.com>2019-10-19 09:47:10 +0300
committerRob Landley <rob@landley.net>2019-10-21 16:58:01 -0500
commit944d818cd97cc5e5d5f710a595405faf075da9d3 (patch)
tree94e8e57782603ec3e8267dccfba530916882f4ec /lib
parent4e0d246ec98f2576d52eb5fd70cd6e86d542e2e4 (diff)
downloadtoybox-944d818cd97cc5e5d5f710a595405faf075da9d3.tar.gz
lib: getdirname fix seqfault on null ptr
In order to be used as drop in replacement for dirname() If path is a null pointer or points to an empty string, dirname() shall return a pointer to the string "." .
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 55b09b85..22b85b06 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1013,7 +1013,7 @@ char *getdirname(char *name)
char *s, *ss, *keep;
for (s = name, ss = keep = 0; ; s++) {
- if (!*s) return keep ? xstrndup(name, keep-name) : xstrdup(".");
+ if (!s || !*s) return keep ? xstrndup(name, keep-name) : xstrdup(".");
if (*s != '/') keep = ss;
else if (s == name) keep = ss = s+1;
else if (s[-1] != '/') ss = s;