X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=path.c;h=f788028a63dbd9b34563d2589697f4b5d65b8648;hb=b5cf3c8b7767e5f2c8b0df718ef91ccfc36c61fe;hp=7ef0d1b80d926d832816a587ddff721cb03130b3;hpb=6b7242aa1acc3c7835f80522914ffc4b2e789a29;p=git.git diff --git a/path.c b/path.c index 7ef0d1b8..f788028a 100644 --- a/path.c +++ b/path.c @@ -41,10 +41,12 @@ char *mkpath(const char *fmt, ...) char *git_path(const char *fmt, ...) { - const char *git_dir = gitenv(GIT_DIR_ENVIRONMENT) ? : DEFAULT_GIT_DIR_ENVIRONMENT; + const char *git_dir; va_list args; unsigned len; + git_dir = getenv(GIT_DIR_ENVIRONMENT); + if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; len = strlen(git_dir); if (len > PATH_MAX-100) return bad_path; @@ -68,8 +70,13 @@ int git_mkstemp(char *path, size_t len, const char *template) if ((env = getenv("TMPDIR")) == NULL) { strcpy(pch, "/tmp/"); len -= 5; - } else - len -= snprintf(pch, len, "%s/", env); + pch += 5; + } else { + size_t n = snprintf(pch, len, "%s/", env); + + len -= n; + pch += n; + } safe_strncpy(pch, template, len);