]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix crash when PWD is set to empty string
authorleo-arch <leonardoabramovich2@gmail.com>
Sun, 14 May 2023 20:12:04 +0000 (20:12 +0000)
committerGitHub <noreply@github.com>
Sun, 14 May 2023 20:12:04 +0000 (20:12 +0000)
nnn crashes when PWD is set to empty string: `PWD="" nnn`

src/nnn.c

index 46e95c5f7964051495089b34eeaa63c7acf7b909..2878a14911789d59dc6be211d36032b46b709e19 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -8716,7 +8716,7 @@ int main(int argc, char *argv[])
                        /* Start in the current directory */
                        char *startpath = getenv("PWD");
 
-                       initpath = startpath ? xstrdup(startpath) : getcwd(NULL, 0);
+                       initpath = (startpath && *startpath) ? xstrdup(startpath) : getcwd(NULL, 0);
                        if (!initpath)
                                initpath = "/";
                } else { /* Open a file */