From 642956cf455ff8635be32b3160b12369da73cfe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 10 Aug 2017 22:56:40 +0200 Subject: strbuf: clear errno before calling getdelim(3) getdelim(3) returns -1 at the end of the file and if it encounters an error, but sets errno only in the latter case. Set errno to zero before calling it to avoid misdiagnosing an out-of-memory condition due to a left-over value from some other function call. Reported-by: Yaroslav Halchenko Suggested-by: Junio C Hamano Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- strbuf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'strbuf.c') diff --git a/strbuf.c b/strbuf.c index ace58e736..977acba31 100644 --- a/strbuf.c +++ b/strbuf.c @@ -472,6 +472,7 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term) /* Translate slopbuf to NULL, as we cannot call realloc on it */ if (!sb->alloc) sb->buf = NULL; + errno = 0; r = getdelim(&sb->buf, &sb->alloc, term, fp); if (r > 0) { -- cgit v1.2.1