From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/519 Path: news.gmane.org!not-for-mail From: Pascal Cuoq Newsgroups: gmane.linux.lib.musl.general Subject: Undefined behavior in atoi() Date: Sun, 6 Nov 2011 15:24:00 +0100 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=e89a8f6428c887592904b111b00d X-Trace: dough.gmane.org 1320589458 23716 80.91.229.12 (6 Nov 2011 14:24:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 6 Nov 2011 14:24:18 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-520-gllmg-musl=m.gmane.org@lists.openwall.com Sun Nov 06 15:24:14 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1RN3dt-0007DE-QZ for gllmg-musl@lo.gmane.org; Sun, 06 Nov 2011 15:24:13 +0100 Original-Received: (qmail 14311 invoked by uid 550); 6 Nov 2011 14:24:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 14303 invoked from network); 6 Nov 2011 14:24:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=ckC8DMp8XoazKOPnjRyZDQKbputm+6+ZhzG64zBlOy4=; b=qRCWZfAsicFlhCl1c8o8eF1ayF4KcuRQiPUx+MuuCojzmls2j1mueCZa/TNahjwAxH hn0OAA5CWBAXCjLogzuS8MyBpzk/hW6pJkMqFJ35wG2h1SNXg9j5Y9SV64+Krh4rmHLn 25X3Z+NLxptVW1u99mNJ75nv8798nSLrkD+48= Xref: news.gmane.org gmane.linux.lib.musl.general:519 Archived-At: --e89a8f6428c887592904b111b00d Content-Type: multipart/alternative; boundary=e89a8f6428c887592604b111b00b --e89a8f6428c887592604b111b00b Content-Type: text/plain; charset=ISO-8859-1 Hello, the attached patch against musl-0.8.3 removes an undefined behavior when atoi() is applied to the representation of INT_MIN. The undefined behavior is not observable if the compiler implements 2's complement for signed arithmetic overflows, but the compiler doesn't have to. On the other hand, C99 mandates either two's complement's lopsided representation of integers or other, symmetrical, representations (6.2.6.2), so I think the patch is an overall improvement. The patch applies in musl-0.8.3/src/stdlib/ and contains identical changes for atol() and atoll(). Regards, Pascal --e89a8f6428c887592604b111b00b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

the attached patch against musl-0.8.3=A0
removes an undefined behavior when atoi()
is applied to the rep= resentation of INT_MIN.

The undefined=A0behavior i= s not observable
if the compiler implements 2's complement
for signed ari= thmetic overflows, but the compiler
doesn't=A0have to.
<= div>
On the other hand, C99 mandates either two's complem= ent's
lopsided representation of integers or=A0other,
symmetrical,= representations (6.2.6.2), so I think the patch
is an overall im= provement.

The patch applies in=A0musl-0.8.3/src/s= tdlib/
and contains identical changes for atol() and atoll().

<= /div>
Regards,

Pascal

--e89a8f6428c887592604b111b00b-- --e89a8f6428c887592904b111b00d Content-Type: application/octet-stream; name=patch_atoi Content-Disposition: attachment; filename=patch_atoi Content-Transfer-Encoding: base64 X-Attachment-Id: f_guo4raev0 LS0tIGF0b2wub3JpZy5jCTIwMTEtMTEtMDYgMTQ6NDk6MjQuMDAwMDAwMDAwICswMTAwCisrKyBh dG9sLmMJMjAxMS0xMS0wNiAxNDo1MjoxNi4wMDAwMDAwMDAgKzAxMDAKQEAgLTEwLDcgKzEwLDkg QEAKIAljYXNlICctJzogbmVnPTE7CiAJY2FzZSAnKyc6IHMrKzsKIAl9CisgIC8qIENvbXB1dGUg biBhcyBhIG5lZ2F0aXZlIG51bWJlciB0byBhdm9pZCB1bmRlZmluZWQgYmVoYXZpb3IgCisgICAg I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