aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-11-25 12:08:38 +0100
committerJunio C Hamano <gitster@pobox.com>2012-11-26 13:32:14 -0800
commit6360bee4cd902bdea5db5826821edffd6f367d89 (patch)
tree46278f8688e50de8f1866e6f8984b4bf29495df7
parent3a34e62684b6dc0edf1301eb2259132ffc233c48 (diff)
downloadgit-6360bee4cd902bdea5db5826821edffd6f367d89.tar.gz
git-6360bee4cd902bdea5db5826821edffd6f367d89.tar.xz
imap-send: correctly report errors reading from stdin
Previously, read_message() didn't distinguish between an error and eof when reading its input. This could have resulted in incorrect behavior if there was an error: (1) reporting "nothing to send" if no bytes were read or (2) sending an incomplete message if some bytes were read before the error. Change read_message() to return -1 on ferror()s and 0 on success, so that the caller can recognize that an error occurred. (The return value used to be the length of the input read, which was redundant because that is already available as the strbuf length. Change the caller to report errors correctly. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--imap-send.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/imap-send.c b/imap-send.c
index 50e223a2a..86cf60396 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1398,7 +1398,7 @@ static int read_message(FILE *f, struct strbuf *all_msgs)
break;
} while (!feof(f));
- return all_msgs->len;
+ return ferror(f) ? -1 : 0;
}
static int count_messages(struct strbuf *all_msgs)
@@ -1537,7 +1537,12 @@ int main(int argc, char **argv)
}
/* read the messages */
- if (!read_message(stdin, &all_msgs)) {
+ if (read_message(stdin, &all_msgs)) {
+ fprintf(stderr, "error reading input\n");
+ return 1;
+ }
+
+ if (all_msgs.len == 0) {
fprintf(stderr, "nothing to send\n");
return 1;
}