From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#30408: Checking for loss of information on integer conversion Date: Thu, 29 Mar 2018 11:09:45 -0700 Organization: UCLA Computer Science Department Message-ID: References: <7432641a-cedc-942c-d75c-0320fce5ba39@cs.ucla.edu> <83y3jq9q4m.fsf@gnu.org> <83605fdtm9.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------0A202BB77F423E21318F69EF" X-Trace: blaine.gmane.org 1522346892 30169 195.159.176.226 (29 Mar 2018 18:08:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 29 Mar 2018 18:08:12 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Cc: 30408-done@debbugs.gnu.org, David Sitsky To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 29 20:08:07 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1f1by2-0007jr-PM for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Mar 2018 20:08:07 +0200 Original-Received: from localhost ([::1]:45571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1c06-0000Ln-BV for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Mar 2018 14:10:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1bzz-0000J5-6U for bug-gnu-emacs@gnu.org; Thu, 29 Mar 2018 14:10:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1bzu-0006cd-1n for bug-gnu-emacs@gnu.org; Thu, 29 Mar 2018 14:10:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1bzt-0006cO-UN for bug-gnu-emacs@gnu.org; Thu, 29 Mar 2018 14:10:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1f1bzt-0000UP-Oi for bug-gnu-emacs@gnu.org; Thu, 29 Mar 2018 14:10:01 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Mar 2018 18:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 30408 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 30408@debbugs.gnu.org, eggert@cs.ucla.edu, david.sitsky@gmail.com Original-Received: via spool by 30408-done@debbugs.gnu.org id=D30408.15223469961863 (code D ref 30408); Thu, 29 Mar 2018 18:10:01 +0000 Original-Received: (at 30408-done) by debbugs.gnu.org; 29 Mar 2018 18:09:56 +0000 Original-Received: from localhost ([127.0.0.1]:58977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f1bzn-0000Tz-QB for submit@debbugs.gnu.org; Thu, 29 Mar 2018 14:09:56 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:50110) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f1bzl-0000Tl-In for 30408-done@debbugs.gnu.org; Thu, 29 Mar 2018 14:09:54 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E5832160AD0; Thu, 29 Mar 2018 11:09:47 -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 PkRft8wklFtm; Thu, 29 Mar 2018 11:09:46 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 379BB1616D4; Thu, 29 Mar 2018 11:09:46 -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 wuVvZSSGhs4u; Thu, 29 Mar 2018 11:09:46 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 1DEA8160AD0; Thu, 29 Mar 2018 11:09:46 -0700 (PDT) In-Reply-To: <83605fdtm9.fsf@gnu.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:144701 Archived-At: This is a multi-part message in MIME format. --------------0A202BB77F423E21318F69EF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 03/29/2018 04:11 AM, Eli Zaretskii wrote: > I'd suggest, for a good measure, to have a variable which would force > the conversion to floats, avoiding an error even without the trailing > period. We can later remove that variable, or make it a no-op, if the > danger of breaking existing code turns out low or non-existent. OK, I did that, by installing the attached into master, after installing the proposed patch. As a result, unless the user sets the new variable read-integer-overflow-as-float, the Lisp reader now rejects the program (format "%x" 2738188573457603759) by signaling an overflow error. As this was the basis of the original bug report, I'm marking the bug as done. --------------0A202BB77F423E21318F69EF Content-Type: text/x-patch; name="0001-New-experimental-variable-read-integer-overflow-as-f.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-New-experimental-variable-read-integer-overflow-as-f.pa"; filename*1="tch" >From c213f465ba8038ce93314b96fd53ec3e35d34609 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 29 Mar 2018 11:01:38 -0700 Subject: [PATCH] New experimental variable read-integer-overflow-as-float. Following a suggestion by Eli Zaretskii (Bug#30408#46). * etc/NEWS: Mention it. * src/lread.c (syms_of_lread): Add it. (read1): Treat out-of-range integers as floats if read-integer-overflow-as-float is non-nil. --- etc/NEWS | 6 ++++-- src/lread.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 9161f2bd32..9dddc90213 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -356,8 +356,10 @@ implementation to format (Bug#30408). ** The Lisp reader now signals an overflow for plain decimal integers that do not end in '.' and are outside Emacs range. Formerly the Lisp reader silently converted them to floating-point numbers, and signaled -overflow only for integers with a radix that are outside machine range -(Bug#30408). +overflow only for integers with a radix that are outside machine range. +To get the old behavior, set the new, experimental variable +read-integer-overflow-as-float to t and please email +30408@debbugs.gnu.org if you need that. (Bug#30408). --- ** Some functions and variables obsolete since Emacs 22 have been removed: diff --git a/src/lread.c b/src/lread.c index a774524ee4..8fb61f5633 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3502,7 +3502,9 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) if (!quoted && !uninterned_symbol) { - Lisp_Object result = string_to_number (read_buffer, 10, 0); + int flags = (read_integer_overflow_as_float + ? S2N_OVERFLOW_TO_FLOAT : 0); + Lisp_Object result = string_to_number (read_buffer, 10, flags); if (! NILP (result)) return unbind_to (count, result); } @@ -4830,6 +4832,13 @@ were read in. */); doc: /* Non-nil means read recursive structures using #N= and #N# syntax. */); Vread_circle = Qt; + DEFVAR_BOOL ("read-integer-overflow-as-float", + read_integer_overflow_as_float, + doc: /* Non-nil means `read' quietly treats an out-of-range integer as floating point. +Nil (the default) means signal an overflow unless the integer ends in `.'. +This variable is experimental; email 30408@debbugs.gnu.org if you need it. */); + read_integer_overflow_as_float = false; + DEFVAR_LISP ("load-path", Vload_path, doc: /* List of directories to search for files to load. Each element is a string (directory file name) or nil (meaning -- 2.14.3 --------------0A202BB77F423E21318F69EF--