@matheusbsbs / matheus-bagliano / commits / fb74243636
Fork 0

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>

Samuel Tardieu committed Oct 6, 2008 at 19:28 UTC fb7424363643d6049faf3bda399e5e602782b5b7
1 file changed +4 -1
index-pack.c
+4 -1
@@ -365,8 +365,11 @@ static void *get_data_from_pack(struct object_entry *obj)
365 data = src;
366 do {
367 ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);
368 - if (n <= 0)
368 + if (n < 0)
369 die("cannot pread pack file: %s", strerror(errno));
370 + if (!n)
371 + die("premature end of pack file, %lu bytes missing",
372 + len - rdy);
373 rdy += n;
374 } while (rdy < len);
375 data = xmalloc(obj->size);