]> granicus.if.org Git - php/commitdiff
- Fixed bug #54970 (SplFixedArray::setSize() isn't resizing)
authorFelipe Pena <felipe@php.net>
Thu, 2 Jun 2011 00:40:27 +0000 (00:40 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 2 Jun 2011 00:40:27 +0000 (00:40 +0000)
NEWS
ext/spl/spl_fixedarray.c
ext/spl/tests/bug54970.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 8dae6c4b7d44997971c9f81a9b7bfee6095f0a08..9f1a977a5c3620fe67c3cca9808c4fd089265ecd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -154,6 +154,7 @@ PHP                                                                        NEWS
   . Fixed bug #51958 (socket_accept() fails on IPv6 server sockets). (Gustavo)
 
 - SPL extension:
+  . Fixed bug #54970 (SplFixedArray::setSize() isn't resizing). (Felipe)
   . Fixed bug #54384 (Dual iterators, GlobIterator, SplFileObject and
     SplTempFileObject crash when user-space classes don't call the paren
     constructor). (Gustavo)
index 791ba216db1c9d0188661387a490b0b19a7c50b5..87a3a02f939675804c9bec7a2e1c3e3a1f9f9df1 100644 (file)
@@ -153,6 +153,8 @@ static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {
        int  i = 0;
 
        if (intern->array) {
+               int j = zend_hash_num_elements(intern->std.properties);
+
                for (i = 0; i < intern->array->size; i++) {
                        if (intern->array->elements[i]) {
                                zend_hash_index_update(intern->std.properties, i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
@@ -165,6 +167,11 @@ static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {
                                Z_ADDREF_P(EG(uninitialized_zval_ptr));
                        }
                }
+               if (j > intern->array->size) {
+                       for (i = intern->array->size; i < j; ++i) {
+                               zend_hash_index_del(intern->std.properties, i);
+                       }
+               }
        }
 
        return intern->std.properties;
diff --git a/ext/spl/tests/bug54970.phpt b/ext/spl/tests/bug54970.phpt
new file mode 100644 (file)
index 0000000..62b1eed
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+Bug #54970 (SplFixedArray::setSize() isn't resizing)
+--FILE--
+<?php
+
+$fa = new SplFixedArray(2);
+$fa[0] = 'Hello';
+$fa[1] = 'World';
+$fa->setSize(3);
+$fa[2] = '!';
+var_dump($fa);
+$fa->setSize(2);
+var_dump($fa);
+var_dump($fa->getSize());
+
+
+?>
+--EXPECTF--
+object(SplFixedArray)#%d (3) {
+  [0]=>
+  string(5) "Hello"
+  [1]=>
+  string(5) "World"
+  [2]=>
+  string(1) "!"
+}
+object(SplFixedArray)#%d (2) {
+  [0]=>
+  string(5) "Hello"
+  [1]=>
+  string(5) "World"
+}
+int(2)