summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2013-02-24 12:55:46 +0800
committerXinchen Hui <laruence@php.net>2013-02-24 12:55:53 +0800
commit1b58bd39a637e9ec4ea9e95903b74aefdbd1b596 (patch)
tree88a8623346e0e2f04836fc5834f7266f968fd97f /ext
parentfcd4b5335a6df4e0676ee32e2267ca71d70fe623 (diff)
downloadphp-git-1b58bd39a637e9ec4ea9e95903b74aefdbd1b596.tar.gz
Fixed bug #64264 (SPLFixedArray toArray problem)
Diffstat (limited to 'ext')
-rw-r--r--ext/spl/spl_fixedarray.c24
-rw-r--r--ext/spl/tests/bug64264.phpt29
2 files changed, 42 insertions, 11 deletions
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 1d18afd04a..646c002f6f 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -611,8 +611,6 @@ SPL_METHOD(SplFixedArray, count)
SPL_METHOD(SplFixedArray, toArray)
{
spl_fixedarray_object *intern;
- zval *ret, *tmp;
- HashTable *ret_ht, *obj_ht;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) {
return;
@@ -620,15 +618,19 @@ SPL_METHOD(SplFixedArray, toArray)
intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
- ALLOC_HASHTABLE(ret_ht);
- zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0);
- ALLOC_INIT_ZVAL(ret);
- Z_TYPE_P(ret) = IS_ARRAY;
- obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC);
- zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
- Z_ARRVAL_P(ret) = ret_ht;
-
- RETURN_ZVAL(ret, 1, 1);
+ array_init(return_value);
+ if (intern->array) {
+ int i = 0;
+ for (; i < intern->array->size; i++) {
+ if (intern->array->elements[i]) {
+ zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
+ Z_ADDREF_P(intern->array->elements[i]);
+ } else {
+ zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
+ Z_ADDREF_P(EG(uninitialized_zval_ptr));
+ }
+ }
+ }
}
/* }}} */
diff --git a/ext/spl/tests/bug64264.phpt b/ext/spl/tests/bug64264.phpt
new file mode 100644
index 0000000000..e7b695bd82
--- /dev/null
+++ b/ext/spl/tests/bug64264.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #64264 (SPLFixedArray toArray problem)
+--FILE--
+<?php
+class MyFixedArray extends \SplFixedArray {
+ protected $foo;
+ protected $bar;
+}
+
+$myFixedArr = new MyFixedArray(1);
+$myFixedArr[0] = 'foo';
+$myFixedArr->setSize(2);
+$myFixedArr[1] = 'bar';
+$myFixedArr->setSize(5);
+$array = $myFixedArr->toArray();
+$array[2] = "ERROR";
+$array[3] = "ERROR";
+$array[4] = "ERROR";
+unset($array[4]);
+$myFixedArr->setSize(2);
+
+print_r($myFixedArr->toArray());
+?>
+--EXPECTF--
+Array
+(
+ [0] => foo
+ [1] => bar
+)