checkout-index: fix --temp relative path mangling
[gitweb.git] / path.c
diff --git a/path.c b/path.c
index 4ef1b01e05bc1b32d337d13a1b654e4993ea0456..f10c91a92708d2e9915aa2855658243d90a4b9df 100644 (file)
--- a/path.c
+++ b/path.c
@@ -249,9 +249,7 @@ int validate_headref(const char *path)
 static struct passwd *getpw_str(const char *username, size_t len)
 {
        struct passwd *pw;
-       char *username_z = xmalloc(len + 1);
-       memcpy(username_z, username, len);
-       username_z[len] = '\0';
+       char *username_z = xmemdupz(username, len);
        pw = getpwnam(username_z);
        free(username_z);
        return pw;
@@ -265,12 +263,12 @@ static struct passwd *getpw_str(const char *username, size_t len)
 char *expand_user_path(const char *path)
 {
        struct strbuf user_path = STRBUF_INIT;
-       const char *first_slash = strchrnul(path, '/');
        const char *to_copy = path;
 
        if (path == NULL)
                goto return_null;
        if (path[0] == '~') {
+               const char *first_slash = strchrnul(path, '/');
                const char *username = path + 1;
                size_t username_len = first_slash - username;
                if (username_len == 0) {