]> granicus.if.org Git - git/commitdiff
strbuf: clear errno before calling getdelim(3)
authorRené Scharfe <l.s.r@web.de>
Thu, 10 Aug 2017 20:56:40 +0000 (22:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Aug 2017 21:41:51 +0000 (14:41 -0700)
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>
strbuf.c

index ace58e7367300975e118660ed2004c7d0885481c..977acba31b6cecc6aa6e8f8070d2faee2a93529a 100644 (file)
--- 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) {