andrey Mon May 2 07:01:14 2005 EDT
Modified files:
/php-src/ext/standard math.c
/php-src/ext/standard/tests/math math_std_dev.phpt
Log:
fix division by zero. throw an warning if the array is empty.
http://cvs.php.net/diff.php/php-src/ext/standard/math.c?r1=1.120&r2=1.121&ty=u
Index: php-src/ext/standard/math.c
diff -u php-src/ext/standard/math.c:1.120 php-src/ext/standard/math.c:1.121
--- php-src/ext/standard/math.c:1.120 Mon May 2 05:17:49 2005
+++ php-src/ext/standard/math.c Mon May 2 07:01:13 2005
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: math.c,v 1.120 2005/05/02 09:17:49 andrey Exp $ */
+/* $Id: math.c,v 1.121 2005/05/02 11:01:13 andrey Exp $ */
#include "php.h"
#include "php_math.h"
@@ -1195,6 +1195,10 @@
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) ==
FAILURE) {
return;
}
+ if (zend_hash_num_elements(Z_ARRVAL_P(arr)) == 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array has zero
elements");
+ RETURN_FALSE;
+ }
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry,
&pos) == SUCCESS) {
convert_to_double_ex(entry);
http://cvs.php.net/diff.php/php-src/ext/standard/tests/math/math_std_dev.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/standard/tests/math/math_std_dev.phpt
diff -u php-src/ext/standard/tests/math/math_std_dev.phpt:1.1
php-src/ext/standard/tests/math/math_std_dev.phpt:1.2
--- php-src/ext/standard/tests/math/math_std_dev.phpt:1.1 Mon May 2
05:17:49 2005
+++ php-src/ext/standard/tests/math/math_std_dev.phpt Mon May 2 07:01:14 2005
@@ -5,6 +5,10 @@
$a=array(4, 1, 7);
$dev=math_std_dev($a);
var_dump(sprintf("%2.9f", $dev));
+var_dump(math_std_dev(array()));
?>
---EXPECT--
-string(11) "2.449489743"
\ No newline at end of file
+--EXPECTF--
+string(11) "2.449489743"
+
+Warning: math_std_dev(): The array has zero elements in %s on line %d
+bool(false)
\ No newline at end of file
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php