From 709869c8bd683472f44a3acc1e96feb6acb6c837 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Thu, 30 May 2024 15:47:25 +0100 Subject: [PATCH] ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0) --- NEWS | 3 +++ ext/bcmath/libbcmath/src/raisemod.c | 2 +- ext/bcmath/tests/bcpowmod_with_mod_1.phpt | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ext/bcmath/tests/bcpowmod_with_mod_1.phpt diff --git a/NEWS b/NEWS index a0d7027019c..1f1dc8a049d 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,9 @@ PHP NEWS . Fixed bug GH-12814 (max_execution_time reached too early on MacOS 14 when running on Apple Silicon). (Manuel Kress) +- BCMatch: + . Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0). (Girgias) + - Curl: . Fixed bug GH-14307 (Test curl_basic_024 fails with curl 8.8.0). (nielsdos) diff --git a/ext/bcmath/libbcmath/src/raisemod.c b/ext/bcmath/libbcmath/src/raisemod.c index bb0d16f6f0a..e1e4587d5d0 100644 --- a/ext/bcmath/libbcmath/src/raisemod.c +++ b/ext/bcmath/libbcmath/src/raisemod.c @@ -81,7 +81,7 @@ zend_result bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, i /* Do the calculation. */ rscale = MAX(scale, power->n_scale); - if ( !bc_compare(modulus, BCG(_one_)) ) + if ( !_bc_do_compare(modulus, BCG(_one_), false, false) ) { bc_free_num (&temp); temp = bc_new_num (1, scale); diff --git a/ext/bcmath/tests/bcpowmod_with_mod_1.phpt b/ext/bcmath/tests/bcpowmod_with_mod_1.phpt new file mode 100644 index 00000000000..95c25443dd3 --- /dev/null +++ b/ext/bcmath/tests/bcpowmod_with_mod_1.phpt @@ -0,0 +1,16 @@ +--TEST-- +bcpowmod() must return 0 when mod is +1 or -1 +--EXTENSIONS-- +bcmath +--FILE-- + +--EXPECT-- +string(1) "0" +string(5) "0.000" +string(1) "0" +string(5) "0.000"