Skip to content

Commit 642956c

Browse files
rscharfegitster
authored andcommitted
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>
1 parent 3d9c5b5 commit 642956c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

strbuf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
472472
/* Translate slopbuf to NULL, as we cannot call realloc on it */
473473
if (!sb->alloc)
474474
sb->buf = NULL;
475+
errno = 0;
475476
r = getdelim(&sb->buf, &sb->alloc, term, fp);
476477

477478
if (r > 0) {

0 commit comments

Comments
 (0)