From: Quentin Rameau <quinq@fifth.space>
To: musl@lists.openwall.com
Subject: Re: [musl] Bug in atoll strtoll, the output of then differ
Date: Sun, 18 Dec 2022 11:06:14 +0100 [thread overview]
Message-ID: <20221218110320.5e3979a4.quinq@fifth.space> (raw)
In-Reply-To: <f1c6f16a-a6fd-8447-5f9b-d3d25a044af4@gmail.com>
> Hello !
Hi,
> 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".
>
> =====
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
> const char *s = "9223372036854775808";
> long long ll = atoll(s);
> long long ll2 = strtoll (s, (char **) NULL, 10);
> int imax = 0x7fffffff;
> printf("%s : %lld : %lld : %d : %d\n", s, ll, ll2, imax, ll <= imax);
> return 0;
> }
This is not a bug in musl, but a bug in the code,
9223372036854775808 is outside the range of long long,
so the behavior is undefined.
As recommended by the standard, ato* should only be used if the input
is known to always be in the target range,
otherwise use the strto* functins and do proper error handling.
next prev parent reply other threads:[~2022-12-18 10:06 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 [this message]
2022-12-18 12:23 ` Szabolcs Nagy
2022-12-18 15:25 ` Rich Felker
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=20221218110320.5e3979a4.quinq@fifth.space \
--to=quinq@fifth.space \
--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).