[PATCH 2/2] strtol.3: EXAMPLES: Fix error checking

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

 



If strtol(3) returns 0 and sets errno to something different than
EINVAL, the call succeeded, or so we interpret from the standards.

POSIX allows libc functions to set errno in success, and it only
specifies two errors for strtol(3) for which it can return 0:

-  Unsupported base.  (errno must be set to EINVAL.)
-  No conversion performed.  (errno might be set to EINVAL.)

If errno is anything else, POSIX doesn't specify, so it can only be a
successful call strtol(3) that read "0" and set errno for spurious
reasons that are allowed.

Cc: Florian Weimer <fweimer@xxxxxxxxxx>
Cc: Iker Pedrosa <ipedrosa@xxxxxxxxxx>
Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>
---
 man3/strtol.3 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/man3/strtol.3 b/man3/strtol.3
index a5082a761..be8cc81d9 100644
--- a/man3/strtol.3
+++ b/man3/strtol.3
@@ -264,7 +264,8 @@ .SS Program source
     /* Check for various possible errors */
 \&
     if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
-            || (errno != 0 && val == 0)) {
+        || (errno == EINVAL && 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