From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Moreton Newsgroups: gmane.emacs.devel Subject: integer overflow handling for most-negative-fixnum Date: Thu, 19 Jul 2018 03:39:32 +0100 Message-ID: <867elsq78b.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1531967902 30010 195.159.176.226 (19 Jul 2018 02:38:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 19 Jul 2018 02:38:22 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 19 04:38:18 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 1ffypd-0007kB-0Y for ged-emacs-devel@m.gmane.org; Thu, 19 Jul 2018 04:38:17 +0200 Original-Received: from localhost ([::1]:39269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffyrj-00050u-R1 for ged-emacs-devel@m.gmane.org; Wed, 18 Jul 2018 22:40:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffyr6-00050m-94 for emacs-devel@gnu.org; Wed, 18 Jul 2018 22:39:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffyr3-0002SW-Mc for emacs-devel@gnu.org; Wed, 18 Jul 2018 22:39:48 -0400 Original-Received: from [195.159.176.226] (port=44533 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ffyr3-0002SH-DB for emacs-devel@gnu.org; Wed, 18 Jul 2018 22:39:45 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1ffyor-00073j-Q1 for emacs-devel@gnu.org; Thu, 19 Jul 2018 04:37:29 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 41 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:3MJGQeIwhFGX7E7NyB81RCCUlgc= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:227559 Archived-At: The patches for bug#30408 contained this testcase: > +(ert-deftest read-large-integer () > + (should-error (read (format "%d0" most-negative-fixnum)) > + :type 'overflow-error) > + (should-error (read (format "%+d" (* -8.0 most-negative-fixnum))) > + :type 'overflow-error) > + (should-error (read (substring (format "%d" most-negative-fixnum) 1)) > + :type 'overflow-error) These tests are all reasonable, as these numbers are definitely out of fixnum range. > + (should-error (read (format "#x%x" most-negative-fixnum)) > + :type 'overflow-error) > + (should-error (read (format "#o%o" most-negative-fixnum)) > + :type 'overflow-error) However, these tests (and the overflow behaviour) seem completely wrong to me. The reported error is for an out of range fixnum, when what was tested was an explicitly valid integer value. Why are non-base10 numbers treated as signed ? Why can they not be treated as unsigned, so the hex and octal values can be read as valid input ? ELISP> most-negative-fixnum -2305843009213693952 (#o200000000000000000000, #x2000000000000000) ELISP> -2305843009213693952 -2305843009213693952 (#o200000000000000000000, #x2000000000000000) ELISP> #o200000000000000000000 *** Read error *** Arithmetic overflow error: "200000000000000000000 is out of fixnum range; maybe set ‘read-integer-overflow-as-float’?" ELISP> #x2000000000000000 *** Read error *** Arithmetic overflow error: "2000000000000000 is out of fixnum range; maybe set ‘read-integer-overflow-as-float’?" Why does the error message ignore the base of the input value ? It should give a more accurate description of the problematic input. AndyM