From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 792 invoked from network); 18 Dec 2022 10:06:40 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 18 Dec 2022 10:06:40 -0000 Received: (qmail 9703 invoked by uid 550); 18 Dec 2022 10:06:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 9671 invoked from network); 18 Dec 2022 10:06:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fifth.space; s=20190812; t=1671357980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1fvstAOBtjOFiKCwpxxdIDXXnKM8UaadlKLOOyqmdso=; b=S6m1VyPzUED5477jRRVUG4t11YjGnTFs3rEirV1hyxtMDqMTaIAehfivJvzN+8wr8xuc1Y tMDNjLjfxLKYtnhySPnSjAmUWgKTlH756MaV1I8hxmOaWqyhbuoe6WUPkAWegRO0aVixwx 6FsIgjSPzzBZzGoY1Ij2J3pJtPuLRs5yFX0J0yP4tTBoBKU9tWQEQZwPazFe3gsykhIBM+ /qkmG5yLw15cHGxE7uyON0oRoNly3r0x2OAL12Q2L7WJCkpFAZ3ea95IPIZDqr9JljyQu9 cXf/D+jO0ptV626gltUb8BRD2Escl9ZyaTfaNYGk3OyKsnmAF1M5lbw699JTHw== Date: Sun, 18 Dec 2022 11:06:14 +0100 From: Quentin Rameau To: musl@lists.openwall.com Message-ID: <20221218110320.5e3979a4.quinq@fifth.space> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] Bug in atoll strtoll, the output of then differ > Hello ! Hi, > Doing some work with emscripten with this project=20 > https://github.com/mingodad/CG-SQL-Lua-playground I was getting some=20 > errors with the usage of "atoll" and with this small program to compare=20 > the output of "musl" and "glibc" I found what seems to be a bug in=20 > "atoll" because with "musl" it gives a different output than "strtoll". >=20 > =3D=3D=3D=3D=3D >=20 > #include > #include >=20 > int main(int argc, char *argv[]) > { > =C2=A0=C2=A0 =C2=A0const char *s =3D "9223372036854775808"; > =C2=A0=C2=A0 =C2=A0long=C2=A0 long ll =3D atoll(s); > =C2=A0=C2=A0 =C2=A0long long ll2 =3D strtoll (s, (char **) NULL, 10); > =C2=A0=C2=A0 =C2=A0int imax =3D 0x7fffffff; > =C2=A0=C2=A0 =C2=A0printf("%s : %lld : %lld : %d : %d\n",=C2=A0 s, ll, l= l2, imax, ll <=3D imax); > =C2=A0=C2=A0 =C2=A0return 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.