summaryrefslogtreecommitdiff
path: root/ext/bcmath/libbcmath/src
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2017-09-07 00:38:08 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2017-09-07 00:38:59 +0200
commitd01453b1294d4c937c344b567fb37be546dfdf43 (patch)
tree28d10d2ca1802010dadd1e282c8b92bdc0ef61e1 /ext/bcmath/libbcmath/src
parent5ce744091c4c51fae7e46d48d146f35479094e3a (diff)
parent0f88a49fd511e6c68d004cc4aecd7aae76dbd63f (diff)
downloadphp-git-d01453b1294d4c937c344b567fb37be546dfdf43.tar.gz
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1)
Diffstat (limited to 'ext/bcmath/libbcmath/src')
-rw-r--r--ext/bcmath/libbcmath/src/raisemod.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/ext/bcmath/libbcmath/src/raisemod.c b/ext/bcmath/libbcmath/src/raisemod.c
index 72a838a364..84a7321ea7 100644
--- a/ext/bcmath/libbcmath/src/raisemod.c
+++ b/ext/bcmath/libbcmath/src/raisemod.c
@@ -75,17 +75,24 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale)
/* Do the calculation. */
rscale = MAX(scale, base->n_scale);
- while ( !bc_is_zero(exponent) )
+ if ( !bc_compare(mod, BCG(_one_)) )
{
- (void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0);
- if ( !bc_is_zero(parity) )
+ temp = bc_new_num (1, scale);
+ }
+ else
+ {
+ while ( !bc_is_zero(exponent) )
{
- bc_multiply (temp, power, &temp, rscale);
- (void) bc_modulo (temp, mod, &temp, scale);
+ (void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0);
+ if ( !bc_is_zero(parity) )
+ {
+ bc_multiply (temp, power, &temp, rscale);
+ (void) bc_modulo (temp, mod, &temp, scale);
+ }
+
+ bc_multiply (power, power, &power, rscale);
+ (void) bc_modulo (power, mod, &power, scale);
}
-
- bc_multiply (power, power, &power, rscale);
- (void) bc_modulo (power, mod, &power, scale);
}
/* Assign the value. */