On Tue, Jan 18, 2022 at 6:22 AM Andreas Schwab <schwab@xxxxxxxxxxxxxx> wrote: > > On Jan 18 2022, xuyang2018.jy@xxxxxxxxxxx wrote: > > > Now, I use glibc-2.34 and run the following program[1] but the errno is > > not 0 in the beginning. So is this a known bug on glibc-2.34(Theodore > > doesn't meet this problem on glicb-2.31)? > > > > [1]https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/tree/src/ext4_resize.c > > Note that there is a call to open preceding the strtoull call, so no > guarantees can be made about the value of errno before the latter. > strtoull man page: RETURN VALUE The strtoul() function returns either the result of the conversion or, if there was a leading minus sign, the negation of the result of the conversion represented as an unsigned value, unless the original (non‐ negated) value would overflow; in the latter case, strtoul() returns ULONG_MAX and sets errno to ERANGE. Precisely the same holds for str‐ toull() (with ULLONG_MAX instead of ULONG_MAX). new_size = strtoull(argv[2], &tmp, 10); if ((errno) || (*tmp != '\0')) { ^^^^^^^^^^^^ Shouldn't errno be checked only after the prior function return value is checked first? fprintf(stderr, "%s: invalid new size\n", argv[0]); return 1; } -- H.J.