* [PATCH] Do not use errno when pread() returns 0
@ 2008-10-06 17:28 Samuel Tardieu
0 siblings, 0 replies; only message in thread
From: Samuel Tardieu @ 2008-10-06 17:28 UTC (permalink / raw)
To: git; +Cc: Samuel Tardieu
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>
---
index-pack.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/index-pack.c b/index-pack.c
index 2e4c088..73860bf 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);
--
tg: (395ff9b..) short-pread (depends on: spearce/next)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2008-10-06 17:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-06 17:28 [PATCH] Do not use errno when pread() returns 0 Samuel Tardieu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).