diff options
author | Gustavo André dos Santos Lopes <cataphract@php.net> | 2011-06-12 00:56:18 +0000 |
---|---|---|
committer | Gustavo André dos Santos Lopes <cataphract@php.net> | 2011-06-12 00:56:18 +0000 |
commit | a54847a0fbfa7e585cd82e71db697dc663593061 (patch) | |
tree | 61950a16e7b58201346cf5d044e2358591b61982 | |
parent | 6a504c6f6b9960df5d5841a8a7fa26dbd5744895 (diff) | |
download | php-git-a54847a0fbfa7e585cd82e71db697dc663593061.tar.gz |
- Reverted r301991, which is a (partial) fix to bug #52550, addressing an
overflow in a signed subtraction. This fixes the overflow without
changing the algorithm.
-rw-r--r-- | ext/standard/math.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c index aabd94b66c..6c679696c4 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -13,7 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Jim Winstead <jimw@php.net> | - | Stig Sæther Bakken <ssb@php.net> | + | Stig Sæther Bakken <ssb@php.net> | | Zeev Suraski <zeev@zend.com> | | PHP 4.0 patches by Thies C. Arntzen <thies@thieso.net> | +----------------------------------------------------------------------+ @@ -92,6 +92,18 @@ static inline double php_intpow10(int power) { } /* }}} */ +/* {{{ php_math_is_finite */ +static inline int php_math_is_finite(double value) { +#if defined(PHP_WIN32) + return _finite(value); +#elif defined(isfinite) + return isfinite(value); +#else + return value == value && (value == 0. || value * 2. != value); +#endif +} +/* }}} */ + /* {{{ php_round_helper Actually performs the rounding of a value to integer in a certain mode */ static inline double php_round_helper(double value, int mode) { @@ -129,11 +141,11 @@ PHPAPI double _php_math_round(double value, int places, int mode) { double tmp_value; int precision_places; - if ((precision_places = php_intlog10abs(value)) > 0) { - precision_places = 14 - php_intlog10abs(value); - } else { - precision_places = 14; + if (!php_math_is_finite(value)) { + return value; } + + precision_places = 14 - php_intlog10abs(value); f1 = php_intpow10(abs(places)); |