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 <yoh@onerussian.com> Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 10, 2017 at 22:56 UTC
642956cf455ff8635be32b3160b12369da73cfe2
1 file changed
+1
strbuf.c
+1
@@ -472,6 +472,7 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
472
/* Translate slopbuf to NULL, as we cannot call realloc on it */
473
if (!sb->alloc)
474
sb->buf = NULL;
475
+ errno = 0;
476
r = getdelim(&sb->buf, &sb->alloc, term, fp);
477
478
if (r > 0) {