Skip to content

Commit fb74243

Browse files
samueltardieuspearce
authored andcommitted
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 <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 0a2c7ee commit fb74243

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index-pack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,11 @@ static void *get_data_from_pack(struct object_entry *obj)
365365
data = src;
366366
do {
367367
ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
368-
if (n <= 0)
368+
if (n < 0)
369369
die("cannot pread pack file: %s", strerror(errno));
370+
if (!n)
371+
die("premature end of pack file, %lu bytes missing",
372+
len - rdy);
370373
rdy += n;
371374
} while (rdy < len);
372375
data = xmalloc(obj->size);

0 commit comments

Comments
 (0)