From: Thomas Roessler Date: Mon, 12 Feb 2001 10:30:41 +0000 (+0000) Subject: Fix mutt_read_line's behaviour when encountering an EOF. From Aaron X-Git-Tag: mutt-1-3-15-rel~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d5fdc71c15d328d4e06531a9096ecee3d6a0602;p=mutt Fix mutt_read_line's behaviour when encountering an EOF. From Aaron Lehmann . --- diff --git a/lib.c b/lib.c index 9db9ffd8..84974a26 100644 --- a/lib.c +++ b/lib.c @@ -464,18 +464,28 @@ char *mutt_read_line (char *s, size_t *size, FILE *fp, int *line) return s; offset = ch - s - 1; } - else if (feof (fp)) - { - /* The last line of fp isn't \n terminated */ - (*line)++; - return s; - } else { - /* There wasn't room for the line -- increase ``s'' */ - offset = *size - 1; /* overwrite the terminating 0 */ - *size += STRING; - safe_realloc ((void **) &s, *size); + int c; + c = getc (fp); /* This is kind of a hack. We want to know if the + char at the current point in the input stream is EOF. + feof() will only tell us if we've already hit EOF, not + if the next character is EOF. So, we need to read in + the next character and manually check if it is EOF. */ + if (c == EOF) + { + /* The last line of fp isn't \n terminated */ + (*line)++; + return s; + } + else + { + ungetc (c, fp); /* undo our dammage */ + /* There wasn't room for the line -- increase ``s'' */ + offset = *size - 1; /* overwrite the terminating 0 */ + *size += STRING; + safe_realloc ((void **) &s, *size); + } } } }