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 <>
This commit is contained in:
René Scharfe 2017-08-10 22:56:40 +02:00 committed by Junio C Hamano
parent 3d9c5b5c44
commit 642956cf45
1 changed files with 1 additions and 0 deletions

View File

@ -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) {