summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2016-01-20 09:46:09 +0100
committerAnatol Belski <ab@php.net>2016-01-20 00:49:05 +0100
commita6801092abb0fc72892177c3f96ab5f795759f35 (patch)
tree4be308356ea4609522a7a2312b02dd8912ba4645
parentf7e6ff99d7633da3ab3cfa4e80e879a31ee8ab29 (diff)
downloadphp-git-a6801092abb0fc72892177c3f96ab5f795759f35.tar.gz
improve fix for bug #71201php-7.0.3RC1
-rw-r--r--ext/standard/math.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 7ea8dc1199..ebfee8ead8 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -146,6 +146,7 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
return value;
}
+ places = places < INT_MIN+1 ? INT_MIN+1 : places;
precision_places = 14 - php_intlog10abs(value);
f1 = php_intpow10(abs(places));
@@ -154,8 +155,10 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
the requested places BUT is small enough to make sure a non-zero value
is returned, pre-round the result to the precision */
if (precision_places > places && precision_places - places < 15) {
- f2 = php_intpow10(abs(precision_places));
- if (precision_places >= 0) {
+ int64_t use_precision = precision_places < INT_MIN+1 ? INT_MIN+1 : precision_places;
+
+ f2 = php_intpow10(abs((int)use_precision));
+ if (use_precision >= 0) {
tmp_value = value * f2;
} else {
tmp_value = value / f2;
@@ -163,8 +166,11 @@ PHPAPI double _php_math_round(double value, int places, int mode) {
/* preround the result (tmp_value will always be something * 1e14,
thus never larger than 1e15 here) */
tmp_value = php_round_helper(tmp_value, mode);
+
+ use_precision = places - precision_places;
+ use_precision = use_precision < INT_MIN+1 ? INT_MIN+1 : use_precision;
/* now correctly move the decimal point */
- f2 = php_intpow10(abs(places - precision_places));
+ f2 = php_intpow10(abs((int)use_precision));
/* because places < precision_places */
tmp_value = tmp_value / f2;
} else {