On Wed, Apr 26, 2017 at 10:20:16PM +0200, Johannes Schindelin wrote:
> diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
> index 30681681c13..c0d88f97512 100644
> --- a/builtin/mailsplit.c
> +++ b/builtin/mailsplit.c
> @@ -232,7 +232,7 @@ static int split_mbox(const char *file, const char *dir,
> int allow_bare,
>
> do {
> peek = fgetc(f);
> - } while (isspace(peek));
> + } while (peek >= 0 && isspace(peek));
> ungetc(peek, f);
Are we guaranteed that EOF is a negative number? Also, what is the
behavior of ungetc when we pass it EOF?
It looks like POSIX does what we want (pushing EOF is a noop, and the
stream retains its feof() status), but I don't know if there are other
implementations to worry about.
Perhaps:
/* soak up whitespace */
while ((peek = fgetc(f)) != EOF) {
if (!isspace(peek)) {
ungetc(peek, f);
break;
}
}
would be more portable.
-Peff