]> granicus.if.org Git - php/commitdiff
Fixed bug #38464 (array_count_values() mishandles numeric strings).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 6 Sep 2006 17:25:57 +0000 (17:25 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 6 Sep 2006 17:25:57 +0000 (17:25 +0000)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug38464.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 51b6c142396a5827d06938f761a06e1c51c2bdeb..4d92272370ccb4f56b11be0c56ed5ca8c1e9e8e0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,7 +6,8 @@
 - Fixed bug #38700 (SoapClient::__getTypes never returns). (Dmitry)
 - Fixed bug #38693 (curl_multi_add_handle() set curl handle to null). (Ilia)
 - Fixed bug #38661 (mixed-case URL breaks url-wrappers). (Ilia)
-
+- Fixed bug #38464 (array_count_values() mishandles numeric strings). 
+  (php_lists at realplain dot com, Ilia)
 
 31 Aug 2006, PHP 5.2.0RC3
 - Updated PCRE to version 6.7. (Ilia)
index 800bbddd8c0b20fe65ab056338c6e39d14488bf9..ab48d549234a281341e30c65028a1f703b0e13a1 100644 (file)
@@ -2548,46 +2548,17 @@ PHP_FUNCTION(array_count_values)
                                                                         (void**)&tmp) == FAILURE) {
                                zval *data;
                                MAKE_STD_ZVAL(data);
-                               Z_TYPE_P(data) = IS_LONG;
-                               Z_LVAL_P(data) = 1;
+                               ZVAL_LONG(data, 1);
                                zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
                        } else {
                                Z_LVAL_PP(tmp)++;
                        }
                } else if (Z_TYPE_PP(entry) == IS_STRING) {
-                       /* make sure our array does not end up with numeric string keys
-                        * but don't touch those strings that start with 0 */
-                       if (!(Z_STRLEN_PP(entry) > 1 && Z_STRVAL_PP(entry)[0] == '0') && is_numeric_string(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), NULL, NULL, 0) == IS_LONG) {
-                               zval tmp_entry;
-                               
-                               tmp_entry = **entry;
-                               zval_copy_ctor(&tmp_entry);
-
-                               convert_to_long(&tmp_entry);
-
-                               if (zend_hash_index_find(Z_ARRVAL_P(return_value), 
-                                                                                Z_LVAL(tmp_entry), 
-                                                                                (void**)&tmp) == FAILURE) {
-                                       zval *data;
-                                       MAKE_STD_ZVAL(data);
-                                       Z_TYPE_P(data) = IS_LONG;
-                                       Z_LVAL_P(data) = 1;
-                                       zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL(tmp_entry), &data, sizeof(data), NULL);
-                               } else {
-                                       Z_LVAL_PP(tmp)++;
-                               }
-                               
-                               zval_dtor(&tmp_entry);
-                               zend_hash_move_forward_ex(myht, &pos);
-                               continue;
-                       }
-               
-                       if (zend_hash_find(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)+1, (void**)&tmp) == FAILURE) {
+                       if (zend_symtable_find(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, (void**)&tmp) == FAILURE) {
                                zval *data;
                                MAKE_STD_ZVAL(data);
-                               Z_TYPE_P(data) = IS_LONG;
-                               Z_LVAL_P(data) = 1;
-                               zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
+                               ZVAL_LONG(data, 1);
+                               zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
                        } else {
                                Z_LVAL_PP(tmp)++;
                        }
diff --git a/ext/standard/tests/array/bug38464.phpt b/ext/standard/tests/array/bug38464.phpt
new file mode 100644 (file)
index 0000000..42f7a6a
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #38464 (array_count_values() mishandles numeric strings)
+--FILE--
+<?php
+$array = array('-000', ' 001', 1, ' 123', '+123');
+var_dump(array_count_values($array));
+?>
+--EXPECT--     
+array(5) {
+  ["-000"]=>
+  int(1)
+  [" 001"]=>
+  int(1)
+  [1]=>
+  int(1)
+  [" 123"]=>
+  int(1)
+  ["+123"]=>
+  int(1)
+}