diff options
author | Jeff King <peff@peff.net> | 2016-10-03 16:36:04 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-10-10 13:52:36 -0700 |
commit | 38dbe5f07837afceaec95fae5981d36eeb4917bd (patch) | |
tree | c8b54f0504b7c23df0927b393faf0fe5dc6256e1 /sha1_name.c | |
parent | afbba2f09ab06424d8b38908f4d76a1503f49a25 (diff) | |
download | git-38dbe5f07837afceaec95fae5981d36eeb4917bd.tar.gz |
alternates: store scratch buffer as strbuf
We pre-size the scratch buffer to hold a loose object
filename of the form "xx/yyyy...", which leads to allocation
code that is hard to verify. We have to use some magic
numbers during the initial allocation, and then writers must
blindly assume that the buffer is big enough. Using a strbuf
makes it more clear that we cannot overflow.
Unfortunately, we do still need some magic numbers to grow
our strbuf before calling fill_sha1_path(), but the strbuf
growth is much closer to the point of use. This makes it
easier to see that it's correct, and opens the possibility
of pushing it even further down if fill_sha1_path() learns
to work on strbufs.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/sha1_name.c b/sha1_name.c index 770ea4fe80..defbb3eb05 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -92,15 +92,12 @@ static void find_short_object_filename(int len, const char *hex_pfx, struct disa xsnprintf(hex, sizeof(hex), "%.2s", hex_pfx); for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) { + struct strbuf *buf = alt_scratch_buf(alt); struct dirent *de; DIR *dir; - /* - * every alt_odb struct has 42 extra bytes after the base - * for exactly this purpose - */ - xsnprintf(alt->name, 42, "%.2s/", hex_pfx); - dir = opendir(alt->scratch); + strbuf_addf(buf, "%.2s/", hex_pfx); + dir = opendir(buf->buf); if (!dir) continue; |