From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Arkadiusz Drabczyk <arkadiusz@drabczyk.org>
Cc: mtk.manpages@gmail.com, linux-man@vger.kernel.org
Subject: Re: [PATCH] atoi.3: Explain disadvantages of atoi()
Date: Fri, 19 Jun 2020 14:26:21 +0200 [thread overview]
Message-ID: <f2230a74-ceb3-a081-a328-129160289960@gmail.com> (raw)
In-Reply-To: <20200618204241.14476-1-arkadiusz@drabczyk.org>
Hello Arkadiusz,
On 6/18/20 10:42 PM, Arkadiusz Drabczyk wrote:
> I believe new users should be discouraged from using atoi() and that
> its disadvantages should be explained.
>
> I added the information that 0 is returned on error - although C
> standard and POSIX say that "If the value of the result cannot be
> represented, the behavior is undefined." there are some
> interpretations that 0 has to be returned
> https://stackoverflow.com/questions/38393162/what-can-i-assume-about-the-behaviour-of-atoi-on-error
> and this is also what happens in practice with glibc, musl and uClibc.
>
> Signed-off-by: Arkadiusz Drabczyk <arkadiusz@drabczyk.org>
Thanks. Patch applied. I also made a few small tweaks. The
results have been pushed to master.
Thanks,
Michael
> ---
> man3/atoi.3 | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/man3/atoi.3 b/man3/atoi.3
> index c5894d3..3c6527a 100644
> --- a/man3/atoi.3
> +++ b/man3/atoi.3
> @@ -81,7 +81,18 @@ functions behave the same as
> except that they convert the initial portion of the
> string to their return type of \fIlong\fP or \fIlong long\fP.
> .SH RETURN VALUE
> -The converted value.
> +The converted value or 0 on error.
> +.SH BUGS
> +.I errno
> +is not set on error so there is no way to distinguish between 0 as an
> +error and as the converted value.
> +No checks for overflow or underflow are done.
> +Only input in decimal base can be converted.
> +It's recommended to use
> +.BR strtol ()
> +and
> +.BR strtoul ()
> +family of functions in new programs.
> .SH ATTRIBUTES
> For an explanation of the terms used in this section, see
> .BR attributes (7).
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
prev parent reply other threads:[~2020-06-19 12:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 20:42 [PATCH] atoi.3: Explain disadvantages of atoi() Arkadiusz Drabczyk
2020-06-19 12:26 ` Michael Kerrisk (man-pages) [this message]
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=f2230a74-ceb3-a081-a328-129160289960@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=arkadiusz@drabczyk.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).