Fix (round 1e+INF) core dump

* src/bignum.c (double_to_integer): Signal an error
if D cannot be converted, instead of dumping core.
* test/src/floatfns-tests.el (special-round): New test.
This commit is contained in:
Paul Eggert 2018-09-11 11:30:48 -07:00
parent fa3785ea5f
commit 038a09041a
2 changed files with 20 additions and 1 deletions

View file

@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "lisp.h"
#include <math.h>
#include <stdlib.h>
/* mpz global temporaries. Making them global saves the trouble of
@ -64,10 +65,13 @@ bignum_to_double (Lisp_Object n)
return mpz_get_d (XBIGNUM (n)->value);
}
/* Return D, converted to a Lisp integer. Discard any fraction. */
/* Return D, converted to a Lisp integer. Discard any fraction.
Signal an error if D cannot be converted. */
Lisp_Object
double_to_integer (double d)
{
if (!isfinite (d))
overflow_error ();
mpz_set_d (mpz[0], d);
return make_integer_mpz ();
}

View file

@ -94,4 +94,19 @@
(or (/= cdelta fdelta)
(zerop (% (round n d) 2)))))))))))
(ert-deftest special-round ()
(let ((ns '(-1e+INF 1e+INF -1 1 -1e+NaN 1e+NaN)))
(dolist (n ns)
(unless (<= (abs n) 1)
(should-error (ceiling n))
(should-error (floor n))
(should-error (round n))
(should-error (truncate n)))
(dolist (d ns)
(unless (<= (abs (/ n d)) 1)
(should-error (ceiling n d))
(should-error (floor n d))
(should-error (round n d))
(should-error (truncate n d)))))))
(provide 'floatfns-tests)