[PATCH] src/ext4_resize.c: set errno to 0 before the strtoull call

Andreas Schwab schwab@linux-m68k.org
Tue Jan 18 15:30:02 GMT 2022


On Jan 18 2022, H.J. Lu via Libc-alpha wrote:

>> Something like:
>>
>>          errno = 0; /* must be cleared to distinguish error */
> ^^^^^^^^^^^^^^^^^ Remove it.

You cannot remove that.  strtoull will not modify errno when there is no
error, so if you want to distinguish a valid return value from an
erroneous one you need to clear errno before the call.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoul.html

    Since 0, {ULONG_MAX}, and {ULLONG_MAX} are returned on error and are
    also valid returns on success, an application wishing to check for error
    situations should set errno to 0, then call strtoul() or strtoull(),
    then check errno.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


More information about the Libc-alpha mailing list