From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: integer overflow handling for most-negative-fixnum Date: Mon, 23 Jul 2018 10:30:15 -0700 Organization: UCLA Computer Science Department Message-ID: <85674d39-4e97-cec6-b40a-cd31bf71b690@cs.ucla.edu> References: <867elsq78b.fsf@gmail.com> <866018yl76.fsf@gmail.com> <1d61916e-efa5-62f9-b76e-afb7da8665fd@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------FD6AD4716987FAA6762DE2D9" X-Trace: blaine.gmane.org 1532366913 22305 195.159.176.226 (23 Jul 2018 17:28:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 23 Jul 2018 17:28:33 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 To: Andy Moreton , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 23 19:28:28 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fhedF-0005c7-Ik for ged-emacs-devel@m.gmane.org; Mon, 23 Jul 2018 19:28:25 +0200 Original-Received: from localhost ([::1]:35817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhefK-0008QL-Gx for ged-emacs-devel@m.gmane.org; Mon, 23 Jul 2018 13:30:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhefD-0008Q6-TK for emacs-devel@gnu.org; Mon, 23 Jul 2018 13:30:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhef8-0001lb-QJ for emacs-devel@gnu.org; Mon, 23 Jul 2018 13:30:27 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:36564) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fhef8-0001l8-Ea for emacs-devel@gnu.org; Mon, 23 Jul 2018 13:30:22 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id CCA91160662; Mon, 23 Jul 2018 10:30:20 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id qw47rqr2cFwj; Mon, 23 Jul 2018 10:30:20 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E8AA51606FD; Mon, 23 Jul 2018 10:30:19 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id t2wHb9DrWOdu; Mon, 23 Jul 2018 10:30:19 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.154.30.119]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 9F701160662; Mon, 23 Jul 2018 10:30:19 -0700 (PDT) Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECH In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:227737 Archived-At: This is a multi-part message in MIME format. --------------FD6AD4716987FAA6762DE2D9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Andy Moreton wrote: > I see that you have pushed 57c4bc146b ("0x%x =E2=86=92 %#x in elisp for= mats"), > which will cause breakage as format is not well behaved: >=20 > ELISP> (format "%#x" 1) > "0x1" > ELISP> (format "%#x" 0) > "0" ; Missing "0x" prefix (same misfeature as in C= ) >=20 > ELISP> (format "%#08x" 1) > "0x000001" ; Wrong number of digits printed > ELISP> (format "%#08x" 0) > "00000000" >=20 > For both of the above reasons, this change is not a good idea. Thanks for mentioning the issue, as I had forgotten that (format "%#x" 0)= yields=20 "0" not "0x0". However, I don't see how 57c4bc146b breaks anything. The=20 generated strings are used as nonces or arbitrary labels and as far as I = can see=20 nobody cares whether 0 is printed as "0" or as "0x0". (As none of the cha= nges=20 involve anything like "%#08x" I don't see the relevance of your second ex= ample.) As I understand it 57c4bc146b is merely a nicety; it's certainly not need= ed for=20 correctness now, and it's not needed for correctness even if we change ho= w=20 negative integers are formatted with %x. If I'm wrong and you still see=20 correctness problems please feel free to revert it (though I'd like to kn= ow what=20 the problems are...). I now notice that this wrinkle about 'format' isn't documented despite be= ing=20 longstanding behavior that mirrors the C standard. It should be documente= d, so I=20 installed the attached patch into master to fix the oversight. --------------FD6AD4716987FAA6762DE2D9 Content-Type: text/x-patch; name="0001-format-x-0-yields-0-not-0x0.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-format-x-0-yields-0-not-0x0.patch" =46rom 90256285e107641b064d6ec51a9c5bb03c3eee6a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Jul 2018 10:23:35 -0700 Subject: [PATCH] (format "%#x" 0) yields "0", not "0x0" * doc/lispref/strings.texi (Formatting Strings): * src/editfns.c (Fformat): Document this. --- doc/lispref/strings.texi | 2 +- src/editfns.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index f68199e..2fff3c7 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -1025,7 +1025,7 @@ Formatting Strings =20 The flag @samp{#} specifies an alternate form which depends on the format in use. For @samp{%o}, it ensures that the result begins -with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes the result +with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes nonzero resul= ts with @samp{0x} or @samp{0X}. For @samp{%e} and @samp{%f}, the @samp{#} flag means include a decimal point even if the precision is zero. For @samp{%g}, it always includes a decimal point, and also diff --git a/src/editfns.c b/src/editfns.c index ccc0d27..09f836c 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -4202,7 +4202,7 @@ The - and 0 flags affect the width specifier, as de= scribed below. =20 The # flag means to use an alternate display form for %o, %x, %X, %e, %f, and %g sequences: for %o, it ensures that the result begins with -\"0\"; for %x and %X, it prefixes the result with \"0x\" or \"0X\"; +\"0\"; for %x and %X, it prefixes nonzero results with \"0x\" or \"0X\";= for %e and %f, it causes a decimal point to be included even if the precision is zero; for %g, it causes a decimal point to be included even if the precision is zero, and also forces trailing --=20 2.7.4 --------------FD6AD4716987FAA6762DE2D9--