mruby-bigint (mpz_set_uint64): adjust reallocation size for uint64

The uint64_t value may fit in `mp_limb*n` where n is 1..4.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-09-30 23:11:35 +09:00
parent 5e6d382782
commit 4aa87acfc9
+3 -1
View File
@@ -96,8 +96,10 @@ mpz_set_int(mrb_state *mrb, mpz_t *y, mrb_int v)
static void
mpz_set_uint64(mrb_state *mrb, mpz_t *y, uint64_t u)
{
const size_t len = sizeof(uint64_t) / sizeof(mp_limb);
size_t len = 0;
for (uint64_t u0=u; u0; u0>>=DIG_SIZE,len++)
;
y->sn = (u != 0);
mpz_realloc(mrb, y, len);
for (size_t i=0; i<len; i++) {