Skip to content

Commit

Permalink
Reuse bcmath_check_scale()
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Sep 7, 2024
1 parent 2e88916 commit ac0931d
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ PHP_FUNCTION(bcadd)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -247,8 +246,7 @@ PHP_FUNCTION(bcsub)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -297,8 +295,7 @@ PHP_FUNCTION(bcmul)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -347,8 +344,7 @@ PHP_FUNCTION(bcdiv)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -402,8 +398,7 @@ PHP_FUNCTION(bcmod)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -458,8 +453,7 @@ PHP_FUNCTION(bcpowmod)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 4) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -535,8 +529,7 @@ PHP_FUNCTION(bcpow)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -597,8 +590,7 @@ PHP_FUNCTION(bcsqrt)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(2, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 2) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -642,8 +634,7 @@ PHP_FUNCTION(bccomp)

if (scale_param_is_null) {
scale = BCG(bc_precision);
} else if (scale_param < 0 || scale_param > INT_MAX) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
} else if (bcmath_check_scale(scale_param, 3) == FAILURE) {
RETURN_THROWS();
} else {
scale = (int) scale_param;
Expand Down Expand Up @@ -783,8 +774,7 @@ PHP_FUNCTION(bcscale)
old_scale = BCG(bc_precision);

if (!new_scale_is_null) {
if (new_scale < 0 || new_scale > INT_MAX) {
zend_argument_value_error(1, "must be between 0 and %d", INT_MAX);
if (bcmath_check_scale(new_scale, 1) == FAILURE) {
RETURN_THROWS();
}

Expand Down

0 comments on commit ac0931d

Please sign in to comment.