Skip to content
Browse files

Fixed bug #64264 (SPLFixedArray toArray problem)

  • Loading branch information...
1 parent fcd4b53 commit 1b58bd39a637e9ec4ea9e95903b74aefdbd1b596 @laruence laruence committed
Showing with 43 additions and 11 deletions.
  1. +1 −0 NEWS
  2. +13 −11 ext/spl/spl_fixedarray.c
  3. +29 −0 ext/spl/tests/bug64264.phpt
View
1 NEWS
@@ -3,6 +3,7 @@ PHP NEWS
?? ??? 2013, PHP 5.3.23
- SPL:
+ . Fixed bug #64264 (SPLFixedArray toArray problem). (Laruence)
. Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS).
(patch by kriss@krizalys.com, Laruence)
View
24 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));
+ }
+ }
+ }
}
/* }}} */
View
29 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
+)

0 comments on commit 1b58bd3

Please sign in to comment.
Something went wrong with that request. Please try again.