mirror of
https://github.com/php/php-src.git
synced 2024-11-27 11:53:33 +08:00
bc_raise() can return a scale lower than that passed into it. While most other bcmath calls won't, it's safest to do a quick check that we're only
reducing n_scale, not increasing it.
This commit is contained in:
parent
dc052fe0e5
commit
874661a66e
@ -159,7 +159,8 @@ PHP_FUNCTION(bcadd)
|
||||
php_str2num(&first, Z_STRVAL_PP(left) TSRMLS_CC);
|
||||
php_str2num(&second, Z_STRVAL_PP(right) TSRMLS_CC);
|
||||
bc_add (first, second, &result, scale);
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@ -203,7 +204,8 @@ PHP_FUNCTION(bcsub)
|
||||
php_str2num(&first, Z_STRVAL_PP(left) TSRMLS_CC);
|
||||
php_str2num(&second, Z_STRVAL_PP(right) TSRMLS_CC);
|
||||
bc_sub (first, second, &result, scale);
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@ -247,7 +249,8 @@ PHP_FUNCTION(bcmul)
|
||||
php_str2num(&first, Z_STRVAL_PP(left) TSRMLS_CC);
|
||||
php_str2num(&second, Z_STRVAL_PP(right) TSRMLS_CC);
|
||||
bc_multiply (first, second, &result, scale TSRMLS_CC);
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@ -292,7 +295,8 @@ PHP_FUNCTION(bcdiv)
|
||||
php_str2num(&second, Z_STRVAL_PP(right) TSRMLS_CC);
|
||||
switch (bc_divide (first, second, &result, scale TSRMLS_CC)) {
|
||||
case 0: /* OK */
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@ -370,7 +374,8 @@ PHP_FUNCTION(bcpowmod)
|
||||
php_str2num(&second, right TSRMLS_CC);
|
||||
php_str2num(&mod, modulous TSRMLS_CC);
|
||||
bc_raisemod(first, second, mod, &result, scale TSRMLS_CC);
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@ -415,7 +420,8 @@ PHP_FUNCTION(bcpow)
|
||||
php_str2num(&first, Z_STRVAL_PP(left) TSRMLS_CC);
|
||||
php_str2num(&second, Z_STRVAL_PP(right) TSRMLS_CC);
|
||||
bc_raise (first, second, &result, scale TSRMLS_CC);
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@ -455,7 +461,8 @@ PHP_FUNCTION(bcsqrt)
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
php_str2num(&result, Z_STRVAL_PP(left) TSRMLS_CC);
|
||||
if (bc_sqrt (&result, scale TSRMLS_CC) != 0) {
|
||||
result->n_scale = scale;
|
||||
if (result->n_scale > scale)
|
||||
result->n_scale = scale;
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
|
Loading…
Reference in New Issue
Block a user