]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
man/man3/strtol.3: CAVEATS: Clarify how to perform range checks
authorAlejandro Colomar <alx@kernel.org>
Fri, 21 Mar 2025 22:13:50 +0000 (23:13 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sun, 23 Mar 2025 18:34:00 +0000 (19:34 +0100)
Reported-by: Bruno Haible <bruno@clisp.org>
Co-authored-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
man/man3/strtol.3

index f9c9af4bcbc6fb1b1a98dd2fe017ad2ba69f06fc..2ae48119b9ecd24c8e4db813a455ac07917fb964 100644 (file)
@@ -192,6 +192,7 @@ POSIX.1-2001, C89, SVr4, 4.3BSD.
 .BR strtoll ()
 POSIX.1-2001, C99.
 .SH CAVEATS
+.SS Range checks
 Since
 .BR strtol ()
 can legitimately return 0,
@@ -210,6 +211,19 @@ and then determine if an error occurred by checking whether
 .I errno == ERANGE
 after the call.
 .P
+.in +4n
+.EX
+errno = 0;
+n = strtol(s, &end, base);
+if (end == s)
+       goto no_number;
+if ((errno == ERANGE && n == LONG_MIN) || n < min)
+       goto too_low;
+if ((errno == ERANGE && n == LONG_MAX) || n > max)
+       goto too_high;
+.EE
+.in
+.SS base
 If the
 .I base
 needs to be tested,