Skip to content

Commit d94dcc9

Browse files
committed
fixed raisemod
1 parent 45fc897 commit d94dcc9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ext/bcmath/libbcmath/src/raisemod.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,23 @@ raise_mod_status bc_raisemod(bc_num base, bc_num expo, bc_num mod, bc_num *resul
7474

7575
/* Do the calculation. */
7676
while (!bc_is_zero(exponent)) {
77-
(void) bc_divmod(exponent, BCG(_two_), &exponent, &parity, 0);
77+
bc_num temp_quot = bc_copy_num(exponent);
78+
(void) bc_divmod(exponent, BCG(_two_), &temp_quot, &parity, 0);
79+
bc_free_num(&exponent);
80+
exponent = temp_quot;
81+
7882
if (!bc_is_zero(parity)) {
7983
bc_multiply_ex(temp, power, &temp, scale);
80-
(void) bc_modulo(temp, modulus, &temp, scale);
84+
bc_num temp_rem = bc_copy_num(temp);
85+
(void) bc_modulo(temp, modulus, &temp_rem, scale);
86+
bc_free_num(&temp);
87+
temp = temp_rem;
8188
}
8289
bc_multiply_ex(power, power, &power, scale);
83-
(void) bc_modulo(power, modulus, &power, scale);
90+
bc_num temp_rem = bc_copy_num(power);
91+
(void) bc_modulo(power, modulus, &temp_rem, scale);
92+
bc_free_num(&power);
93+
power = temp_rem;
8494
}
8595

8696
/* Assign the value. */

0 commit comments

Comments
 (0)