This reverts commit 93f369892aeab4d56b92962224e318f739ee2455. That commit was wrong. It is necessary to check both the return value _and_ errno to determine that strtol(3) failed. In fact, the checks are still slightly incorrect, since strtol(3) could succeed and return 0, but still set errno, to something other than EINVAL. Link: Cc: Florian Weimer Cc: Iker Pedrosa Signed-off-by: Alejandro Colomar --- man3/strtol.3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/man3/strtol.3 b/man3/strtol.3 index 01c658025..a5082a761 100644 --- a/man3/strtol.3 +++ b/man3/strtol.3 @@ -261,9 +261,10 @@ .SS Program source errno = 0; /* To distinguish success/failure after call */ val = strtol(str, &endptr, base); \& - /* Check for various possible errors. */ + /* Check for various possible errors */ \& - if (errno != 0) { + if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) + || (errno != 0 && val == 0)) { perror("strtol"); exit(EXIT_FAILURE); } -- 2.42.0