Skip to content

Commit

Permalink
Do not use errno when pread() returns 0
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Samuel Tardieu authored and Shawn O. Pearce committed Oct 8, 2008
1 parent 0a2c7ee commit fb74243
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fb74243

Please sign in to comment.