From: Jeff King Date: Thu, 10 Aug 2017 21:02:46 GMT Subject: Re: [PATCH] strbuf: clear errno before calling getdelim(3) Message-ID: <20170810210246.p4vp2ibahgsii7fc@sigill.intra.peff.net> In-Reply-To: On Thu, Aug 10, 2017 at 10:56:40PM +0200, René Scharfe wrote: > 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. Looks good to me. > Do we need to save and restore the original value of errno? I doubt it, > but didn't think deeply about it, yet. I'd say no. Anybody depending on strbuf_getwholeline() is clearly already wrong in the error case. And in general I think we assume that syscalls can clear errno on success if they choose to (this isn't a syscall, but obviously it is calling some). -Peff