1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-23 20:05:32 +02:00

Limit the range of ash, round-ash count argument to INT32

This avoids gmp aborting e.g. with (ash 1 (expt 2 37)). The new limit is
such that (ash 1 (expt 30)) is accepted but (ash 1 (expt 31)) throws.

Fixes https://bugs.gnu.org/48150

* libguile/numbers.c (ash, round-ash): As stated.
* test-suite/tests/numbers.test: Test a case known to make gmp abort before.
This commit is contained in:
Daniel Llorens 2021-11-04 14:52:21 +01:00
parent ffb33fd66b
commit bf9d30f3c3
2 changed files with 45 additions and 56 deletions

View file

@ -5466,7 +5466,10 @@
(ash-variant -1 (- (expt 2 1000))))
(pass-if-exception "Huge left shift of non-zero => numerical overflow"
exception:numerical-overflow
(ash-variant 123 (expt 2 1000)))))
(ash-variant 123 (expt 2 1000)))
(pass-if-exception "Shift large enough to cause gmp abort in 3.0.7"
exception:numerical-overflow
(ash-variant 1 (expt 2 37)))))
(test-ash-variant 'ash ash floor #f)
(test-ash-variant 'round-ash round-ash round #t)