From: Gustavo André dos Santos Lopes Date: Sun, 12 Jun 2011 00:56:18 +0000 (+0000) Subject: - Reverted r301991, which is a (partial) fix to bug #52550, addressing an X-Git-Tag: php-5.5.0alpha1~1953 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89da1ab1e80086094c617633eb5dde5b14f56707;p=php - 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. --- diff --git a/ext/standard/math.c b/ext/standard/math.c index a4df5a5aa6..e4e884c299 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 | - | Stig Sæther Bakken | + | Stig Sæther Bakken | | Zeev Suraski | | PHP 4.0 patches by Thies C. Arntzen | +----------------------------------------------------------------------+ @@ -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));