aboutsummaryrefslogtreecommitdiffstats
path: root/src/bignum.c
diff options
context:
space:
mode:
authorPaul Eggert2019-06-04 08:13:20 -0700
committerPaul Eggert2019-06-04 08:34:15 -0700
commit7f4558e3d9edbdee6901e5fbcd4a4072f49ec5b9 (patch)
treea709f4f82777f6a5e2c16e7d417ba59b74e7b430 /src/bignum.c
parentdd7bc5de3f59237f21e1c4b70f0ba97549ea1fb4 (diff)
downloademacs-7f4558e3d9edbdee6901e5fbcd4a4072f49ec5b9.tar.gz
emacs-7f4558e3d9edbdee6901e5fbcd4a4072f49ec5b9.zip
Always allow at least double-precision bignums
Without this fix, Emacs can get into a tight loop reporting a range error when calculating timestamps. * doc/lispref/numbers.texi (Integer Basics): * src/alloc.c (syms_of_alloc): Document this. * src/bignum.c (make_bignum_bits): Always allow bignums of at least twice the width of (u)intmax_t.
Diffstat (limited to 'src/bignum.c')
-rw-r--r--src/bignum.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/bignum.c b/src/bignum.c
index 009d73118c2..3883d3a3944 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -82,8 +82,11 @@ static Lisp_Object
82make_bignum_bits (size_t bits) 82make_bignum_bits (size_t bits)
83{ 83{
84 /* The documentation says integer-width should be nonnegative, so 84 /* The documentation says integer-width should be nonnegative, so
85 a single comparison suffices even though 'bits' is unsigned. */ 85 comparing it to BITS works even though BITS is unsigned. Treat
86 if (integer_width < bits) 86 integer-width as if it were at least twice the machine integer width,
87 so that timefns.c can safely use bignums for double-precision
88 timestamps. */
89 if (integer_width < bits && 2 * max (INTMAX_WIDTH, UINTMAX_WIDTH) < bits)
87 overflow_error (); 90 overflow_error ();
88 91
89 struct Lisp_Bignum *b = ALLOCATE_PLAIN_PSEUDOVECTOR (struct Lisp_Bignum, 92 struct Lisp_Bignum *b = ALLOCATE_PLAIN_PSEUDOVECTOR (struct Lisp_Bignum,