Thread (24 messages) 24 messages, 2 authors, 2025-03-23

[PATCH v3 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected

From: Alejandro Colomar <alx@kernel.org>
Date: 2025-03-23 00:30:36
Subsystem: the rest · Maintainer: Linus Torvalds

Link: <https://stackoverflow.com/questions/60955490/strtoul-what-is-the-correct-return-value-for-very-negative-strings>
Reported-by: Bruno Haible <redacted>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 man/man3/strtol.3  |  8 ++++++++
 man/man3/strtoul.3 | 19 ++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/man/man3/strtol.3 b/man/man3/strtol.3
index 9323873a9..03047f10a 100644
--- a/man/man3/strtol.3
+++ b/man/man3/strtol.3
@@ -224,6 +224,14 @@ .SH CAVEATS
     goto unsupported_base;
 .EE
 .in
+.SH BUGS
+.SS White space
+These functions silently accept leading white space.
+One should call
+.BR isspace (3)
+before
+.BR strtol ()
+to reject white space.
 .SH EXAMPLES
 The program shown below demonstrates the use of
 .BR strtol ().
diff --git a/man/man3/strtoul.3 b/man/man3/strtoul.3
index 9eb260dae..9e73190f5 100644
--- a/man/man3/strtoul.3
+++ b/man/man3/strtoul.3
@@ -204,11 +204,20 @@ .SH CAVEATS
 and then determine if an error occurred by checking whether
 .I errno
 has a nonzero value after the call.
-.P
-Negative values are considered valid input and are
-silently converted to the equivalent
-.I "unsigned long"
-value.
+.SH BUGS
+.SS Signed numbers
+Some negative values
+are considered valid input and
+are silently converted to
+.IR "\%unsigned\ long" .
+.SS White space
+These functions silently accept leading whitespace.
+.SS isalnum(3)
+One should call
+.BR isalnum (3)
+before
+.BR strtoul ()
+to reject white space and/or a sign.
 .SH EXAMPLES
 See the example on the
 .BR strtol (3)
-- 
2.47.2

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help