mirror of
https://github.com/php/php-src.git
synced 2025-01-10 13:03:54 +08:00
MFB: Fixed bug #38464 (array_count_values() mishandles numeric strings).
This commit is contained in:
parent
408a584d6e
commit
803b3f4d77
@ -2571,48 +2571,18 @@ PHP_FUNCTION(array_count_values)
|
|||||||
(void**)&tmp) == FAILURE) {
|
(void**)&tmp) == FAILURE) {
|
||||||
zval *data;
|
zval *data;
|
||||||
MAKE_STD_ZVAL(data);
|
MAKE_STD_ZVAL(data);
|
||||||
Z_TYPE_P(data) = IS_LONG;
|
ZVAL_LONG(data, 1);
|
||||||
Z_LVAL_P(data) = 1;
|
|
||||||
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
|
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
|
||||||
} else {
|
} else {
|
||||||
Z_LVAL_PP(tmp)++;
|
Z_LVAL_PP(tmp)++;
|
||||||
}
|
}
|
||||||
} else if (Z_TYPE_PP(entry) == IS_STRING ||
|
} else if (Z_TYPE_PP(entry) == IS_STRING ||
|
||||||
Z_TYPE_PP(entry) == IS_UNICODE) {
|
Z_TYPE_PP(entry) == IS_UNICODE) {
|
||||||
/* make sure our array does not end up with numeric string keys
|
if (zend_u_symtable_find(Z_ARRVAL_P(return_value), Z_TYPE_PP(entry), Z_UNIVAL_PP(entry), Z_UNILEN_PP(entry) + 1, (void**)&tmp) == FAILURE) {
|
||||||
* but don't touch those strings that start with 0 */
|
|
||||||
if ((Z_TYPE_PP(entry) == IS_STRING && !(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) ||
|
|
||||||
(Z_TYPE_PP(entry) == IS_UNICODE && zend_cmp_unicode_and_literal(Z_USTRVAL_PP(entry), 1, "0", sizeof("0")-1) && is_numeric_unicode(Z_USTRVAL_PP(entry), Z_USTRLEN_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_u_hash_find(Z_ARRVAL_P(return_value), Z_TYPE_PP(entry), Z_UNIVAL_PP(entry), Z_UNILEN_PP(entry)+1, (void**)&tmp) == FAILURE) {
|
|
||||||
zval *data;
|
zval *data;
|
||||||
MAKE_STD_ZVAL(data);
|
MAKE_STD_ZVAL(data);
|
||||||
Z_TYPE_P(data) = IS_LONG;
|
ZVAL_LONG(data, 1);
|
||||||
Z_LVAL_P(data) = 1;
|
zend_u_symtable_update(Z_ARRVAL_P(return_value), Z_TYPE_PP(entry), Z_UNIVAL_PP(entry), Z_UNILEN_PP(entry) + 1, &data, sizeof(data), NULL);
|
||||||
zend_u_hash_update(Z_ARRVAL_P(return_value), Z_TYPE_PP(entry), Z_UNIVAL_PP(entry), Z_UNILEN_PP(entry) + 1, &data, sizeof(data), NULL);
|
|
||||||
} else {
|
} else {
|
||||||
Z_LVAL_PP(tmp)++;
|
Z_LVAL_PP(tmp)++;
|
||||||
}
|
}
|
||||||
|
20
ext/standard/tests/array/bug38464.phpt
Normal file
20
ext/standard/tests/array/bug38464.phpt
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user