git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@rfc1149.net>
To: git@vger.kernel.org
Cc: Samuel Tardieu <sam@rfc1149.net>
Subject: [PATCH] Do not use errno when pread() returns 0
Date: Mon,  6 Oct 2008 19:28:41 +0200	[thread overview]
Message-ID: <1223314121-21528-1-git-send-email-sam@rfc1149.net> (raw)

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)

                 reply	other threads:[~2008-10-06 17:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1223314121-21528-1-git-send-email-sam@rfc1149.net \
    --to=sam@rfc1149.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).