Commit:    3380de9774551964af976aa48328e7e6f9bd78ff
Author:    Xinchen Hui <larue...@php.net>         Sun, 21 Jul 2013 21:07:19 
+0800
Parents:   cc91fbe986c208c40b50af8154373693d4bd7c9b
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=3380de9774551964af976aa48328e7e6f9bd78ff

Log:
Fixed bug #65304 (Use of max int in array_sum)

Bugs:
https://bugs.php.net/65304

Changed paths:
  M  NEWS
  M  ext/standard/array.c
  A  ext/standard/tests/array/bug65304.phpt


Diff:
diff --git a/NEWS b/NEWS
index 997a845..ae429c2 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP                                                             
           NEWS
 ?? ??? 2013, PHP 5.4.19
 
 - Core.
+  . Fixed bug #65304 (Use of max int in array_sum). (Laruence)
   . Fixed bug #65291 (get_defined_constants() causes PHP to crash in a very
     limited case). (Arpad)
   . Improve fix for bug #63186 (compile failure on netbsd). (Matteo)
diff --git a/ext/standard/array.c b/ext/standard/array.c
index e218dc0..0eaca16 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -4037,17 +4037,7 @@ PHP_FUNCTION(array_sum)
                entry_n = **entry;
                zval_copy_ctor(&entry_n);
                convert_scalar_to_number(&entry_n TSRMLS_CC);
-
-               if (Z_TYPE(entry_n) == IS_LONG && Z_TYPE_P(return_value) == 
IS_LONG) {
-                       dval = (double)Z_LVAL_P(return_value) + 
(double)Z_LVAL(entry_n);
-                       if ( (double)LONG_MIN <= dval && dval <= 
(double)LONG_MAX ) {
-                               Z_LVAL_P(return_value) += Z_LVAL(entry_n);
-                               continue;
-                       }
-               }
-               convert_to_double(return_value);
-               convert_to_double(&entry_n);
-               Z_DVAL_P(return_value) += Z_DVAL(entry_n);
+               fast_add_function(return_value, return_value, &entry_n 
TSRMLS_CC);
        }
 }
 /* }}} */
diff --git a/ext/standard/tests/array/bug65304.phpt 
b/ext/standard/tests/array/bug65304.phpt
new file mode 100644
index 0000000..e5c9dfc
--- /dev/null
+++ b/ext/standard/tests/array/bug65304.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Bug #65304 (Use of max int in array_sum)
+--FILE--
+<?php
+var_dump(array_sum(array(PHP_INT_MAX, 1)));
+var_dump(PHP_INT_MAX + 1);
+?>
+--EXPECTF--    
+float(%s)
+float(%s)


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to