From 944d818cd97cc5e5d5f710a595405faf075da9d3 Mon Sep 17 00:00:00 2001 From: Jarno Mäkipää Date: Sat, 19 Oct 2019 09:47:10 +0300 Subject: 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 "." . --- lib/lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/lib.c') 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; -- cgit v1.2.3