summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2008-10-06 17:28:41 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2008-10-08 14:38:48 (GMT)
commitfb7424363643d6049faf3bda399e5e602782b5b7 (patch)
tree3b0fae24a1fc6f2c534afec7d4803192667f2dca
parent0a2c7eea41867ead2b2fb1d5898494c3a72405e5 (diff)
downloadgit-fb7424363643d6049faf3bda399e5e602782b5b7.zip
git-fb7424363643d6049faf3bda399e5e602782b5b7.tar.gz
git-fb7424363643d6049faf3bda399e5e602782b5b7.tar.bz2
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 <sam@rfc1149.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--index-pack.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/index-pack.c b/index-pack.c
index 530d820..c45ae20 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);