Web lists-archives.com

Re: [PATCH] strbuf: clear errno before calling getdelim(3)




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.

getdelim(3p) doesn't explicitly forbid changing the errno on EOF:

    If no characters were read, and the end-of-file indicator for
    the stream is set, or if the stream is at end-of-file, the
    end-of-file indicator for the stream shall be set and the
    function shall return −1. If an error occurs, the error
    indicator for the stream shall be set, and the function shall
    return −1 and set errno to indicate the error.

So a valid implementation could still set errno on EOF and also
on another error (where it's required to set errno).

I don't think that it matters in practice, but the "most" correct
way to handle this would be to check if feof(3) is true to check
for the non-errno case.

Regards
Simon
-- 
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9