From: Bruno Haible <bruno@clisp.org>
To: Alejandro Colomar <alx@kernel.org>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH v4 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected
Date: Sun, 23 Mar 2025 16:52:15 +0100 [thread overview]
Message-ID: <2092070.kUgFBCI4xA@nimes> (raw)
In-Reply-To: <xifkkmguez6zsugoxbcz4bukqnnxjidrlw3qmds5wkwb6swq5k@rqj7gtgdvrtt>
Alejandro Colomar wrote:
> Is patch 2/2 also good to you?
I couldn't tell without looking at the entire page
("groff -Tutf8 -mandoc strtol.3 | less -R"). But now...
> <https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=cbcf76d19f864da8c54e41b600ff5661b195b58e>
you gave me the information where to look at your work-in-progress tree.
Here are my findings on these two pages:
* In strtol.3, the example has three mistakes:
- Missing semicolon at the end of the second line.
- If LONG_MIN < min < LONG_MAX, the condition (errno == ERANGE && n == min)
will never be true.
If LONG_MIN < max < LONG_MAX, the condition (errno == ERANGE && n == max)
will never be true.
- It does not distinguish success with value 0 from failure due to
no digits. (This matters when min <= 0 <= max.) Since errno is not
guaranteed to be set in this case, the caller needs to look at *endptr.
The example thus becomes:
char *end;
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;
* strtol.3 and strtoul.3 mention
"If base is zero or 16, the string may then include a "0x" or "0X" prefix,
and the number will be read in base 16"
They should also mention:
"If base is zero or 2, the string may then include a "0b" or "0B" prefix,
and the number will be read in base 2"
References:
- ISO C 23 § 7.24.1.7.(3)
- https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=64924422a99690d147a166b4de3103f3bf3eaf6c
Bruno
next prev parent reply other threads:[~2025-03-23 15:52 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 20:41 [PATCH v1] man/man3/strtoul.3: BUGS: Signed numbers are not rejected Alejandro Colomar
2025-03-21 21:31 ` Bruno Haible
2025-03-21 22:21 ` Alejandro Colomar
2025-03-21 22:18 ` [PATCH v2 0/2] strto[u]l(3) BUGS and CAVEATS Alejandro Colomar
2025-03-21 22:18 ` [PATCH v2 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected Alejandro Colomar
2025-03-21 22:18 ` [PATCH v2 2/2] man/man3/strtol.3: CAVEATS: Clarify how to perform range checks Alejandro Colomar
2025-03-23 0:30 ` [PATCH v3 0/2] strto[u]l.3: BUGS and CAVEATS Alejandro Colomar
2025-03-23 0:30 ` [PATCH v3 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected Alejandro Colomar
2025-03-23 10:27 ` Bruno Haible
2025-03-23 11:15 ` Alejandro Colomar
2025-03-23 0:30 ` [PATCH v3 2/2] man/man3/strtol.3: CAVEATS: Clarify how to perform range checks Alejandro Colomar
2025-03-23 11:43 ` [PATCH v4 0/2] strto[u]l.3: BUGS and CAVEATS Alejandro Colomar
2025-03-23 11:43 ` [PATCH v4 1/2] man/man3/strto[u]l.3: BUGS: Signed numbers and white space are not rejected Alejandro Colomar
2025-03-23 13:20 ` Bruno Haible
2025-03-23 14:00 ` Alejandro Colomar
2025-03-23 15:52 ` Bruno Haible [this message]
2025-03-23 16:55 ` Alejandro Colomar
2025-03-23 17:03 ` Alejandro Colomar
2025-03-23 17:11 ` Bruno Haible
2025-03-23 18:35 ` Alejandro Colomar
2025-03-23 18:55 ` Alejandro Colomar
2025-03-23 19:26 ` Bruno Haible
2025-03-23 19:47 ` Alejandro Colomar
2025-03-23 11:43 ` [PATCH v4 2/2] man/man3/strtol.3: CAVEATS: Clarify how to perform range checks Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2092070.kUgFBCI4xA@nimes \
--to=bruno@clisp.org \
--cc=alx@kernel.org \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.