{"thread":{"id":"15803","subject":"[PATCH] Do not use errno when pread() returns 0","startedAt":"2008-10-06T17:28:41Z","lastAt":"2008-10-06T17:28:41Z","messageCount":1,"participants":["Samuel Tardieu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"92436","messageId":"1223314121-21528-1-git-send-email-sam@rfc1149.net","threadId":"15803","inReplyTo":null,"subject":"[PATCH] Do not use errno when pread() returns 0","fromName":"Samuel Tardieu","fromEmail":"sam@rfc1149.net","sentAt":"2008-10-06T17:28:41Z","receivedAt":"2008-10-06T17:28:41Z","isPatch":true,"sender":{"key":"sam@rfc1149.net","avatar":"https://avatars.githubusercontent.com/u/44656?v=4"},"body":"If we use pread() while at the end of the file, it will return 0, which is\nnot an error from the operating system point of view. In this case, errno\nhas not been set and must not be used.\n\nSigned-off-by: Samuel Tardieu <sam@rfc1149.net>\n\n---\n index-pack.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/index-pack.c b/index-pack.c\nindex 2e4c088..73860bf 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -365,8 +365,11 @@ static void *get_data_from_pack(struct object_entry *obj)\n \tdata = src;\n \tdo {\n \t\tssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy);\n-\t\tif (n <= 0)\n+\t\tif (n < 0)\n \t\t\tdie(\"cannot pread pack file: %s\", strerror(errno));\n+\t\tif (!n)\n+\t\t\tdie(\"premature end of pack file, %lu bytes missing\",\n+\t\t\t    len - rdy);\n \t\trdy += n;\n \t} while (rdy < len);\n \tdata = xmalloc(obj->size);\n-- \ntg: (395ff9b..) short-pread (depends on: spearce/next)\n"}]}