summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-05-16 06:47:21 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-05-16 06:47:21 -0700
commit09e636bf8b26c56953d2c99a3c150fe78bb643ac (patch)
tree1f19be4e2951bb1ce2ffd5987053b7242095918f
parent7e8a0dad42a1a43d13fe45fc6d426f7ee4980721 (diff)
downloadtxr-09e636bf8b26c56953d2c99a3c150fe78bb643ac.tar.gz
txr-09e636bf8b26c56953d2c99a3c150fe78bb643ac.tar.bz2
txr-09e636bf8b26c56953d2c99a3c150fe78bb643ac.zip
random: reject negative bignum modulus.
* rand.c (random): Function now rejects negative bignums, not only negative fixnums.
-rw-r--r--rand.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/rand.c b/rand.c
index e8455b56..a5109701 100644
--- a/rand.c
+++ b/rand.c
@@ -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;