Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix leading-zero-guard condition on bdigit is smaller than 32bit

  • Loading branch information...
commit 1351eacab386c92ae374c5b9762673128bbe1bd0 1 parent 80d1bc1
@Watson1978 Watson1978 authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 random.c
View
11 random.c
@@ -209,18 +209,25 @@ fill_random_seed(unsigned int seed[DEFAULT_SEED_CNT])
static VALUE
make_seed_value(const void *ptr)
{
+ const long len = DEFAULT_SEED_LEN/SIZEOF_BDIGITS;
BDIGIT *digits;
NEWOBJ(big, struct RBignum);
OBJSETUP(big, rb_cBignum, T_BIGNUM);
RBIGNUM_SET_SIGN(big, 1);
- rb_big_resize((VALUE)big, DEFAULT_SEED_LEN / SIZEOF_BDIGITS + 1);
+ rb_big_resize((VALUE)big, len + 1);
digits = RBIGNUM_DIGITS(big);
MEMCPY(digits, ptr, char, DEFAULT_SEED_LEN);
/* set leading-zero-guard if need. */
- digits[RBIGNUM_LEN(big)-1] = digits[RBIGNUM_LEN(big)-2] <= 1 ? 1 : 0;
+ digits[len] =
+#if SIZEOF_INT32 / SIZEOF_BDIGITS > 1
+ digits[len-2] <= 1 && digits[len-1] == 0
+#else
+ digits[len-1] <= 1
+#endif
+ ? 1 : 0;
return rb_big_norm((VALUE)big);
}
Please sign in to comment.
Something went wrong with that request. Please try again.