From 8bd62ca311fbc2e5121a5eaa3f857029c9400cd8 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 11 Dec 2024 20:19:56 +0900 Subject: [PATCH] mruby-bigint (mrb_bint_xor): fix a bug in bigint ^ int operation Fix #6453; ref #6444 --- mrbgems/mruby-bigint/core/bigint.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 449b88978..48b6a63e2 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -1911,15 +1911,15 @@ mrb_bint_xor(mrb_state *mrb, mrb_value x, mrb_value y) mpz_t a, b, c; bint_as_mpz(RBIGINT(x), &a); - if (mrb_integer_p(y)) { + if (mrb_integer_p(y) && a.sn > 0) { mrb_int z = mrb_integer(y); if (z == 0) return x; if (0 < z && (mp_dbl_limb)z < DIG_BASE) { - z ^= a.p[0]; - return mrb_int_value(mrb, z); + mpz_init_set(mrb, &c, &a); + c.p[0] ^= z; + return bint_norm(mrb, bint_new(mrb, &c)); } } - y = mrb_as_bint(mrb, y); bint_as_mpz(RBIGINT(y), &b); if (zero_p(&a)) return y;