mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 14:21:10 +02:00
* random.c: Bugfix: Retrieve and store most significant 32 bits in
different order if the machine is bigendian. (scm_init_random): Added safety check for bignum digit size.
This commit is contained in:
parent
6bcb5a82c3
commit
2a0279c9b8
1 changed files with 21 additions and 0 deletions
|
@ -247,7 +247,11 @@ scm_i_random_bignum (SCM m, scm_rstate *state)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* fix most significant 32 bits */
|
/* fix most significant 32 bits */
|
||||||
|
#if SIZEOF_INT == 4 && defined (WORDS_BIGENDIAN)
|
||||||
|
w = SCM_BDIGITS (m)[nd - 1] << 16 | SCM_BDIGITS (m)[nd - 2];
|
||||||
|
#else
|
||||||
w = ((LONG32 *) SCM_BDIGITS (m))[nd / 2 - 1];
|
w = ((LONG32 *) SCM_BDIGITS (m))[nd / 2 - 1];
|
||||||
|
#endif
|
||||||
mask = (w < 0x10000
|
mask = (w < 0x10000
|
||||||
? (w < 0x100
|
? (w < 0x100
|
||||||
? scm_masktab[w]
|
? scm_masktab[w]
|
||||||
|
@ -274,7 +278,12 @@ scm_i_random_bignum (SCM m, scm_rstate *state)
|
||||||
{
|
{
|
||||||
/* fix most significant 32 bits */
|
/* fix most significant 32 bits */
|
||||||
i /= 2;
|
i /= 2;
|
||||||
|
#if SIZEOF_INT == 4 && defined (WORDS_BIGENDIAN)
|
||||||
|
w = scm_the_rng.random_bits (state) & mask;
|
||||||
|
bits[--i] = (w & 0xffff) << 16 | w >> 16;
|
||||||
|
#else
|
||||||
bits[--i] = scm_the_rng.random_bits (state) & mask;
|
bits[--i] = scm_the_rng.random_bits (state) & mask;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/* now fill up the rest of the bignum */
|
/* now fill up the rest of the bignum */
|
||||||
while (i)
|
while (i)
|
||||||
|
@ -553,5 +562,17 @@ scm_init_random ()
|
||||||
|
|
||||||
#include "random.x"
|
#include "random.x"
|
||||||
|
|
||||||
|
/* Check that the assumptions about bits per bignum digit are correct. */
|
||||||
|
#if SIZEOF_INT == 4
|
||||||
|
m = 16;
|
||||||
|
#else
|
||||||
|
m = 32;
|
||||||
|
#endif
|
||||||
|
if (m != SCM_BITSPERDIG)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Internal inconsistency: Confused about bignum digit size in random.c\n");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
scm_add_feature ("random");
|
scm_add_feature ("random");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue