com php-src: improve fix for bug #71201: ext/standard/math.c

From: Date: Wed, 20 Jan 2016 08:44:28 +0000
Subject: com php-src: improve fix for bug #71201: ext/standard/math.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90705@lists.php.net to get a copy of this message
Commit: 508d1dae25cb5b8a66f84b3686619bc9ab0a68f8 Author: Anatol Belski <ab@php.net> Wed, 20 Jan 2016 09:44:28 +0100 Parents: fa0dd6006d7ea2ac2b8e0d8e9caa82b11d4f9fe1 Branches: PHP-5.6 PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=508d1dae25cb5b8a66f84b3686619bc9ab0a68f8 Log: improve fix for bug #71201 Bugs: https://bugs.php.net/71201 Changed paths: M ext/standard/math.c Diff: diff --git a/ext/standard/math.c b/ext/standard/math.c index b959545..5ffeff7 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -145,6 +145,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)); @@ -153,8 +154,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; @@ -162,8 +165,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 {

« previous php.cvs (#90705) next »