[PATCH 1/2] Revert "strtol.3: EXAMPLES: Simplify errno checking"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: <https://lore.kernel.org/linux-man/ZWiCsBkRpOLEc1Y3@debian/T/#t>
Cc: Florian Weimer <fweimer@xxxxxxxxxx>
Cc: Iker Pedrosa <ipedrosa@xxxxxxxxxx>
Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>
---
 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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux