Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: P modify in history event



Peter Stephenson wrote on Tue, 19 Nov 2019 18:21 +00:00:
> On Tue, 2019-11-19 at 18:00 +0000, Daniel Shahaf wrote:
> > Can «zgetcwd()» return an empty string?  If that's possible, the
> > condition will be undefined behaviour («""[-1]»).
> 
> Not in a sane world, but there are cases where we can't work out the
> current directory.  I think we return "." then, in fact.  But a bit of
> safety probably wouldn't hurt --- applying [-1] to functions arguably
> isn't top class style.

How about this, then?

diff --git a/Src/compat.c b/Src/compat.c
index 7131d91a4..02b66a780 100644
--- a/Src/compat.c
+++ b/Src/compat.c
@@ -519,7 +519,7 @@ zgetcwd(void)
 #endif /* HAVE_GETCWD */
     if (!ret)
 	ret = unmeta(pwd);
-    if (!ret)
+    if (!ret || *ret == '\0')
 	ret = dupstring(".");
     return ret;
 }

Cheers,

Daniel
(let's continue the discussion on -workers@)



Messages sorted by: Reverse Date, Date, Thread, Author