From 8a39e6d6539bd37100cbbfb88916b853f444f771 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 12 Oct 2020 13:42:48 +0900 Subject: bignum.c (rb_int_powm): Integer#pow(0, 1) should return 0 ... instead of 1 because it requires "modulo 1". [Bug #17257] --- bignum.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 65a50ea9ba..cd969ac360 100644 --- a/bignum.c +++ b/bignum.c @@ -7136,6 +7136,7 @@ rb_int_powm(int const argc, VALUE * const argv, VALUE const num) long const half_val = (long)HALF_LONG_MSB; long const mm = FIX2LONG(m); if (!mm) rb_num_zerodiv(); + if (mm == 1) return INT2FIX(0); if (mm <= half_val) { return int_pow_tmp1(rb_int_modulo(a, m), b, mm, nega_flg); } @@ -7145,6 +7146,7 @@ rb_int_powm(int const argc, VALUE * const argv, VALUE const num) } else { if (rb_bigzero_p(m)) rb_num_zerodiv(); + if (bignorm(m) == INT2FIX(1)) return INT2FIX(0); return int_pow_tmp3(rb_int_modulo(a, m), b, m, nega_flg); } } -- cgit v1.2.3