mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Domingo Alvarez Duarte <mingodad@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Bug in atoll strtoll, the output of then differ
Date: Sun, 18 Dec 2022 10:25:22 -0500	[thread overview]
Message-ID: <20221218152521.GC15716@brightrain.aerifal.cx> (raw)
In-Reply-To: <f1c6f16a-a6fd-8447-5f9b-d3d25a044af4@gmail.com>

On Sun, Dec 18, 2022 at 10:32:10AM +0100, Domingo Alvarez Duarte wrote:
> Hello !
> 
> Doing some work with emscripten with this project
> https://github.com/mingodad/CG-SQL-Lua-playground I was getting some
> errors with the usage of "atoll" and with this small program to
> compare the output of "musl" and "glibc" I found what seems to be a
> bug in "atoll" because with "musl" it gives a different output than
> "strtoll".

Everyone's already covered the reason this is not a bug, but to shed
some light on possible motivations for not implementing ato* as
wrappers around strto*:

Aside from making these functions somewhat smaller when static linked
into tiny programs, writing the conversion with arithmetic that
overflows on out-of-bounds inputs rather than handling it as an error
case makes it so that a build of libc with suitable sanitizers would
automatically make ato* trap-and-crash on inputs that have undefined
behavior via the undefinedness of the underlying arithmetic. To do
this with strto* wrappers would require manually checking error cases
and manual alignment of the trap cases with the specification, which
would need review and testing to get the same benefit.

That's not to say it *has to* be done this way. In lots of places in
musl, we do just implement "junk functions" similar to the ato* family
as wrappers around a modern "good function". But being that we already
have it here, I see no reason to change to something that's worse in
most ways.

Rich

      parent reply	other threads:[~2022-12-18 15:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-18  9:32 Domingo Alvarez Duarte
2022-12-18  9:58 ` Markus Wichmann
2022-12-18 10:22   ` Domingo Alvarez Duarte
2022-12-18 11:10     ` Markus Wichmann
2022-12-18 10:06 ` Quentin Rameau
2022-12-18 12:23 ` Szabolcs Nagy
2022-12-18 15:25 ` Rich Felker [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=20221218152521.GC15716@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=mingodad@gmail.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).