From: Paul Eggert <eggert@cs.ucla.edu>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 32476-done@debbugs.gnu.org
Subject: bug#32476: 27.0.50; Assertion failure for dot-terminated large int
Date: Tue, 21 Aug 2018 15:52:38 -0700 [thread overview]
Message-ID: <098c494b-4b76-45e6-376d-ed8ae1d19222@cs.ucla.edu> (raw)
In-Reply-To: <jwvo9dyc6ni.fsf@iro.umontreal.ca>
[-- Attachment #1: Type: text/plain, Size: 64 bytes --]
Thanks for reporting that; I installed the attached to fix it.
[-- Attachment #2: 0001-Fix-assertion-failure-when-reading-BIGNUM.patch --]
[-- Type: text/x-patch, Size: 2994 bytes --]
From f8069952abf147d090032ad6b941a728cad2c496 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@Penguin.CS.UCLA.EDU>
Date: Tue, 21 Aug 2018 15:49:01 -0700
Subject: [PATCH] Fix assertion failure when reading 'BIGNUM.'
Problem reported by Stefan Monnier (Bug#32476).
* src/lread.c (string_to_number): Don't pass leading "+"
or trailing "." or junk to make_bignum_str.
* test/src/lread-tests.el (lread-string-to-number-trailing-dot):
New test.
---
src/lread.c | 21 ++++++++++++++++-----
test/src/lread-tests.el | 9 +++++++++
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index df2fe58120..5e1bd419fa 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3710,8 +3710,9 @@ string_to_number (char const *string, int base, int flags)
IEEE floating point hosts, and works around a formerly-common bug where
atof ("-0.0") drops the sign. */
bool negative = *cp == '-';
+ bool positive = *cp == '+';
- bool signedp = negative || *cp == '+';
+ bool signedp = negative | positive;
cp += signedp;
enum { INTOVERFLOW = 1, LEAD_INT = 2, DOT_CHAR = 4, TRAIL_INT = 8,
@@ -3732,6 +3733,7 @@ string_to_number (char const *string, int base, int flags)
n += digit;
}
}
+ char const *after_digits = cp;
if (*cp == '.')
{
state |= DOT_CHAR;
@@ -3807,10 +3809,19 @@ string_to_number (char const *string, int base, int flags)
return make_fixnum (negative ? -signed_n : signed_n);
}
- /* Skip a leading "+". */
- if (signedp && !negative)
- ++string;
- return make_bignum_str (string, base);
+ /* Trim any leading "+" and trailing nondigits, then convert to
+ bignum. */
+ string += positive;
+ if (!*after_digits)
+ return make_bignum_str (string, base);
+ ptrdiff_t trimmed_len = after_digits - string;
+ USE_SAFE_ALLOCA;
+ char *trimmed = SAFE_ALLOCA (trimmed_len + 1);
+ memcpy (trimmed, string, trimmed_len);
+ trimmed[trimmed_len] = '\0';
+ Lisp_Object result = make_bignum_str (trimmed, base);
+ SAFE_FREE ();
+ return result;
}
/* Either the number uses float syntax, or it does not fit into a fixnum.
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index 17381340c7..f19d98320a 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -209,4 +209,13 @@ lread-tests--last-message
(should-error
(let ((load-force-doc-strings t)) (read "#[0 \"\"]"))))
+(ert-deftest lread-string-to-number-trailing-dot ()
+ (dolist (n (list (* most-negative-fixnum most-negative-fixnum)
+ (1- most-negative-fixnum) most-negative-fixnum
+ (1+ most-negative-fixnum) -1 0 1
+ (1- most-positive-fixnum) most-positive-fixnum
+ (1+ most-positive-fixnum)
+ (* most-positive-fixnum most-positive-fixnum)))
+ (should (= n (string-to-number (format "%d." n))))))
+
;;; lread-tests.el ends here
--
2.17.1
prev parent reply other threads:[~2018-08-21 22:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-19 22:50 bug#32476: 27.0.50; Assertion failure for dot-terminated large int Stefan Monnier
2018-08-21 22:52 ` Paul Eggert [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=098c494b-4b76-45e6-376d-ed8ae1d19222@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=32476-done@debbugs.gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.