cataphract Sun, 12 Jun 2011 00:56:18 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=312074
Log: - 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. Bug: http://bugs.php.net/52550 (Analyzed) integer undefined behaviors executed during "make test" Changed paths: U php/php-src/branches/PHP_5_3/ext/standard/math.c U php/php-src/branches/PHP_5_4/ext/standard/math.c U php/php-src/trunk/ext/standard/math.c Modified: php/php-src/branches/PHP_5_3/ext/standard/math.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/math.c 2011-06-12 00:31:13 UTC (rev 312073) +++ php/php-src/branches/PHP_5_3/ext/standard/math.c 2011-06-12 00:56:18 UTC (rev 312074) @@ -13,7 +13,7 @@ | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Jim Winstead <[email protected]> | - | Stig S�ther Bakken <[email protected]> | + | Stig Sæther Bakken <[email protected]> | | Zeev Suraski <[email protected]> | | PHP 4.0 patches by Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ @@ -92,6 +92,18 @@ } /* }}} */ +/* {{{ 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 @@ 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)); Modified: php/php-src/branches/PHP_5_4/ext/standard/math.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/standard/math.c 2011-06-12 00:31:13 UTC (rev 312073) +++ php/php-src/branches/PHP_5_4/ext/standard/math.c 2011-06-12 00:56:18 UTC (rev 312074) @@ -13,7 +13,7 @@ | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Jim Winstead <[email protected]> | - | Stig S�ther Bakken <[email protected]> | + | Stig Sæther Bakken <[email protected]> | | Zeev Suraski <[email protected]> | | PHP 4.0 patches by Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ @@ -92,6 +92,18 @@ } /* }}} */ +/* {{{ 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 @@ 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)); Modified: php/php-src/trunk/ext/standard/math.c =================================================================== --- php/php-src/trunk/ext/standard/math.c 2011-06-12 00:31:13 UTC (rev 312073) +++ php/php-src/trunk/ext/standard/math.c 2011-06-12 00:56:18 UTC (rev 312074) @@ -13,7 +13,7 @@ | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Jim Winstead <[email protected]> | - | Stig S�ther Bakken <[email protected]> | + | Stig Sæther Bakken <[email protected]> | | Zeev Suraski <[email protected]> | | PHP 4.0 patches by Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ @@ -92,6 +92,18 @@ } /* }}} */ +/* {{{ 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 @@ 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));
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
