summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJim Hill <gjthill@gmail.com>2015-05-18 00:41:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-05-18 17:15:20 (GMT)
commitf6a1e1e288d13472f5f7fe2b907bb8c0bd69a018 (patch)
tree6466b0dfe46eac30cb7174c8c7f20f0418a0f306 /sha1_file.c
parent282616c72d1d08a77ca4fe1186cb708c38408d87 (diff)
downloadgit-f6a1e1e288d13472f5f7fe2b907bb8c0bd69a018.zip
git-f6a1e1e288d13472f5f7fe2b907bb8c0bd69a018.tar.gz
git-f6a1e1e288d13472f5f7fe2b907bb8c0bd69a018.tar.bz2
sha1_file: pass empty buffer to index empty file
`git add` of an empty file with a filter pops complaints from `copy_fd` about a bad file descriptor. This traces back to these lines in sha1_file.c:index_core: if (!size) { ret = index_mem(sha1, NULL, size, type, path, flags); The problem here is that content to be added to the index can be supplied from an fd, or from a memory buffer, or from a pathname. This call is supplying a NULL buffer pointer and a zero size. Downstream logic takes the complete absence of a buffer to mean the data is to be found elsewhere -- for instance, these, from convert.c: if (params->src) { write_err = (write_in_full(child_process.in, params->src, params->size) < 0); } else { write_err = copy_fd(params->fd, child_process.in); } ~If there's a buffer, write from that, otherwise the data must be coming from an open fd.~ Perfectly reasonable logic in a routine that's going to write from either a buffer or an fd. So change `index_core` to supply an empty buffer when indexing an empty file. There's a patch out there that instead changes the logic quoted above to take a `-1` fd to mean "use the buffer", but it seems to me that the distinction between a missing buffer and an empty one carries intrinsic semantics, where the logic change is adapting the code to handle incorrect arguments. Signed-off-by: Jim Hill <gjthill@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index a38854c..6e2d6ec 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3119,7 +3119,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
int ret;
if (!size) {
- ret = index_mem(sha1, NULL, size, type, path, flags);
+ ret = index_mem(sha1, "", size, type, path, flags);
} else if (size <= SMALL_FILE_SIZE) {
char *buf = xmalloc(size);
if (size == read_in_full(fd, buf, size))