Fix assertion failure in mpz_divmod_inpl

.. turning this from an assertion failure into an exception:
    pow(1,1,0)
This commit is contained in:
Jeff Epler 2018-03-25 16:01:06 -05:00 committed by Jeff Epler
parent 1eba580443
commit a55988a547
2 changed files with 9 additions and 0 deletions

View File

@ -343,6 +343,10 @@ mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus) {
mpz_t *rhs = mp_mpz_for_int(exponent, &r_temp);
mpz_t *mod = mp_mpz_for_int(modulus, &m_temp);
if (mpz_is_zero(mod)) {
mp_raise_msg(&mp_type_ValueError, "pow() 3rd argument cannot be 0");
}
mpz_pow3_inpl(&(res_p->mpz), lhs, rhs, mod);
if (lhs == &l_temp) { mpz_deinit(lhs); }

View File

@ -22,3 +22,8 @@ try:
print(pow(4, 5, "z"))
except TypeError:
print("TypeError expected")
try:
print(pow(4, 5, 0))
except ValueError:
print("ValueError expected")