From fb7424363643d6049faf3bda399e5e602782b5b7 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Mon, 6 Oct 2008 19:28:41 +0200 Subject: [PATCH] Do not use errno when pread() returns 0 If we use pread() while at the end of the file, it will return 0, which is not an error from the operating system point of view. In this case, errno has not been set and must not be used. Signed-off-by: Samuel Tardieu Signed-off-by: Shawn O. Pearce --- index-pack.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index-pack.c b/index-pack.c index 530d82037..c45ae20e8 100644 --- a/index-pack.c +++ b/index-pack.c @@ -365,8 +365,11 @@ static void *get_data_from_pack(struct object_entry *obj) data = src; do { ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy); - if (n <= 0) + if (n < 0) die("cannot pread pack file: %s", strerror(errno)); + if (!n) + die("premature end of pack file, %lu bytes missing", + len - rdy); rdy += n; } while (rdy < len); data = xmalloc(obj->size); -- 2.26.2