summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-07-24 10:51:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-24 17:19:29 (GMT)
commit765b496dc6963ad8aaf40e9ac5dee358aa7fea47 (patch)
tree0d0eb4cd2ab22e4c356c098d5fd48f5a37722999 /refs
parentf3e76ed228d60688b49dbc2735e4633e55969e30 (diff)
downloadgit-765b496dc6963ad8aaf40e9ac5dee358aa7fea47.zip
git-765b496dc6963ad8aaf40e9ac5dee358aa7fea47.tar.gz
git-765b496dc6963ad8aaf40e9ac5dee358aa7fea47.tar.bz2
pass st.st_size as hint for strbuf_readlink()
When we initially added the strbuf_readlink() function in b11b7e13f4 (Add generic 'strbuf_readlink()' helper function, 2008-12-17), the point was that we generally have a _guess_ as to the correct size based on the stat information, but we can't necessarily trust it. Over the years, a few callers have grown up that simply pass in 0, even though they have the stat information. Let's have them pass in their hint for consistency (and in theory efficiency, since it may avoid an extra resize/syscall loop, but neither location is probably performance critical). Note that st.st_size is actually an off_t, so in theory we need xsize_t() here. But none of the other callsites use it, and since this is just a hint, it doesn't matter either way (if we wrap we'll simply start with a too-small hint and then eventually complain when we cannot allocate the memory). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index a9a066d..c110c25 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -363,7 +363,7 @@ stat_ref:
/* Follow "normalized" - ie "refs/.." symlinks by hand */
if (S_ISLNK(st.st_mode)) {
strbuf_reset(&sb_contents);
- if (strbuf_readlink(&sb_contents, path, 0) < 0) {
+ if (strbuf_readlink(&sb_contents, path, st.st_size) < 0) {
if (errno == ENOENT || errno == EINVAL)
/* inconsistent with lstat; retry */
goto stat_ref;