com php-src: Return old scale value from bcscale(): ext/bcmath/bcmath.c ext/bcmath/tests/bcscale_variation003.phpt

From: Date: Mon, 18 Aug 2014 12:56:02 +0000
Subject: com php-src: Return old scale value from bcscale(): ext/bcmath/bcmath.c ext/bcmath/tests/bcscale_variation003.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-99420@lists.php.net to get a copy of this message
Commit: 1e3435b2898ea2b9e16ca92064edd8fa1a07b44c Author: Chris Wright <daverandom@php.net> Mon, 18 Aug 2014 13:49:28 +0100 Parents: 35189d2dd68f9451512c018ed26918652f48a4fd Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1e3435b2898ea2b9e16ca92064edd8fa1a07b44c Log: Return old scale value from bcscale() Fix for #67855 Bugs: https://bugs.php.net/67855 Changed paths: M ext/bcmath/bcmath.c A ext/bcmath/tests/bcscale_variation003.phpt Diff: diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index 4b8c7c5..39228ba 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -537,15 +537,19 @@ PHP_FUNCTION(bccomp) Sets default scale parameter for all bc math functions */ PHP_FUNCTION(bcscale) { - long new_scale; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_scale) == FAILURE) { + long old_scale, new_scale; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_scale) == FAILURE) { return; } - BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale; + old_scale = BCG(bc_precision); + + if (ZEND_NUM_ARGS() == 1) { + BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale; + } - RETURN_TRUE; + RETURN_LONG(old_scale); } /* }}} */ diff --git a/ext/bcmath/tests/bcscale_variation003.phpt b/ext/bcmath/tests/bcscale_variation003.phpt new file mode 100644 index 0000000..b1c5416 --- /dev/null +++ b/ext/bcmath/tests/bcscale_variation003.phpt @@ -0,0 +1,18 @@ +--TEST-- +bcscale() return value +--SKIPIF-- +<?php if(!extension_loaded("bcmath")) print "skip"; ?> +--INI-- +bcmath.scale=0 +--FILE-- +<?php +var_dump(bcscale(1)); +var_dump(bcscale(4)); +var_dump(bcscale()); +var_dump(bcscale()); +?> +--EXPECT-- +int(0) +int(1) +int(4) +int(4)

« previous php.cvs (#99420) next »