aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/os/env.c9
-rw-r--r--src/nvim/os/users.c3
2 files changed, 5 insertions, 7 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 7fb4a93b54..25c4cc4f92 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -373,11 +373,10 @@ void expand_env_esc(char_u *restrict srcp,
*var++ = *tail++;
}
*var = NUL;
- // Use os_get_user_directory() to get the user directory.
- // If this function fails, the shell is used to
- // expand ~user. This is slower and may fail if the shell
- // does not support ~user (old versions of /bin/sh).
- var = (char_u *)os_get_user_directory((char *)dst + 1);
+ // Get the user directory. If this fails the shell is used to expand
+ // ~user, which is slower and may fail on old versions of /bin/sh.
+ var = (*dst == NUL) ? NULL
+ : (char_u *)os_get_user_directory((char *)dst + 1);
mustfree = true;
if (var == NULL) {
expand_T xpc;
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index 7c48ac6e5e..c6463c2c92 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -75,11 +75,10 @@ int os_get_uname(uv_uid_t uid, char *s, size_t len)
char *os_get_user_directory(const char *name)
{
#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
- struct passwd *pw;
if (name == NULL || *name == NUL) {
return NULL;
}
- pw = getpwnam(name); // NOLINT(runtime/threadsafe_fn)
+ struct passwd *pw = getpwnam(name); // NOLINT(runtime/threadsafe_fn)
if (pw != NULL) {
// save the string from the static passwd entry into malloced memory
return xstrdup(pw->pw_dir);