diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-05-16 06:47:21 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-05-16 06:47:21 -0700 |
commit | dbff4c5e634e23e3c957260ef8d7ddf59d81dbdb (patch) | |
tree | 1f19be4e2951bb1ce2ffd5987053b7242095918f | |
parent | eed5dd5b038d947f8288111503c6bf48e7e30f17 (diff) | |
download | txr-dbff4c5e634e23e3c957260ef8d7ddf59d81dbdb.tar.gz txr-dbff4c5e634e23e3c957260ef8d7ddf59d81dbdb.tar.bz2 txr-dbff4c5e634e23e3c957260ef8d7ddf59d81dbdb.zip |
random: reject negative bignum modulus.
* rand.c (random): Function now rejects negative bignums, not
only negative fixnums.
-rw-r--r-- | rand.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -220,9 +220,9 @@ val random(val state, val modulus) val self = lit("random"); struct rand_state *r = coerce(struct rand_state *, cobj_handle(state, random_state_s)); + mp_int *m; - if (bignump(modulus)) { - mp_int *m = mp(modulus); + if (bignump(modulus) && !ISNEG(m = mp(modulus))) { ucnum bits = mp_count_bits(m) - mp_is_pow_two(m); ucnum rands_needed = (bits + 32 - 1) / 32; ucnum msb_rand_bits = bits % 32; |