diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-06-21 05:40:41 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-06-21 05:40:41 -0700 |
commit | 951f92d2abb28f59e8207cce13aac3b15c95eeca (patch) | |
tree | f662c615468c80f37daf3d23d06e3602094710f3 | |
parent | d0780b0643123dcf68639ac9fc4d79da4e41e6da (diff) | |
parent | 560fb6a183e1cdbc2948b06cc60bba07f79804a6 (diff) | |
download | git-951f92d2abb28f59e8207cce13aac3b15c95eeca.tar.gz git-951f92d2abb28f59e8207cce13aac3b15c95eeca.tar.xz |
Merge branch 'jk/maint-sha1-file-name-fix' into maint
* jk/maint-sha1-file-name-fix:
remove over-eager caching in sha1_file_name
-rw-r--r-- | sha1_file.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/sha1_file.c b/sha1_file.c index 1efa9154e..72de38909 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -102,20 +102,22 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1) */ char *sha1_file_name(const unsigned char *sha1) { - static char *name, *base; + static char buf[PATH_MAX]; + const char *objdir; + int len; - if (!base) { - const char *sha1_file_directory = get_object_directory(); - int len = strlen(sha1_file_directory); - base = xmalloc(len + 60); - memcpy(base, sha1_file_directory, len); - memset(base+len, 0, 60); - base[len] = '/'; - base[len+3] = '/'; - name = base + len + 1; - } - fill_sha1_path(name, sha1); - return base; + objdir = get_object_directory(); + len = strlen(objdir); + + /* '/' + sha1(2) + '/' + sha1(38) + '\0' */ + if (len + 43 > PATH_MAX) + die("insanely long object directory %s", objdir); + memcpy(buf, objdir, len); + buf[len] = '/'; + buf[len+3] = '/'; + buf[len+42] = '\0'; + fill_sha1_path(buf + len + 1, sha1); + return buf; } static char *sha1_get_pack_name(const unsigned char *sha1, |