summaryrefslogtreecommitdiff
path: root/ext/bcmath/bcmath.c
diff options
context:
space:
mode:
authorVladyslav Startsev <17382248+vladyslavstartsev@users.noreply.github.com>2020-06-20 18:26:51 +0300
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-06-22 09:31:55 +0200
commit2c97b401c61ad09ea0bb0045314b410a97e1d4ac (patch)
tree3cba1bfd15128c6d0c5692f51b2fa03082394885 /ext/bcmath/bcmath.c
parentec80b781dbd1978653b2e20d6b99ed61e65e646f (diff)
downloadphp-git-2c97b401c61ad09ea0bb0045314b410a97e1d4ac.tar.gz
make bcpowmod stricter by not returning false, instead throw exception
Closes GH-5747
Diffstat (limited to 'ext/bcmath/bcmath.c')
-rw-r--r--ext/bcmath/bcmath.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c
index 1b91fba72f..f1e298b5cc 100644
--- a/ext/bcmath/bcmath.c
+++ b/ext/bcmath/bcmath.c
@@ -404,10 +404,16 @@ PHP_FUNCTION(bcpowmod)
php_str2num(&second, ZSTR_VAL(right));
php_str2num(&mod, ZSTR_VAL(modulus));
- if (bc_raisemod(first, second, mod, &result, scale) != -1) {
- RETVAL_STR(bc_num2str_ex(result, scale));
- } else {
- RETVAL_FALSE;
+ switch (bc_raisemod(first, second, mod, &result, scale)) {
+ case 0:
+ RETVAL_STR(bc_num2str_ex(result, scale));
+ break;
+ case -1:
+ zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Modulo by zero");
+ break;
+ case -2:
+ zend_argument_value_error(2, "must be greater than 0");
+ break;
}
bc_free_num(&first);