diff options
author | Jarno Mäkipää <jmakip87@gmail.com> | 2019-10-19 09:47:10 +0300 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-10-21 16:58:01 -0500 |
commit | 944d818cd97cc5e5d5f710a595405faf075da9d3 (patch) | |
tree | 94e8e57782603ec3e8267dccfba530916882f4ec /lib | |
parent | 4e0d246ec98f2576d52eb5fd70cd6e86d542e2e4 (diff) | |
download | toybox-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.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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; |