@@ -309,7 +309,7 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object,
309
309
if (!offset ) {
310
310
return & EG (uninitialized_zval_ptr );
311
311
}
312
-
312
+
313
313
if ((type == BP_VAR_W || type == BP_VAR_RW ) && (ht -> nApplyCount > 0 )) {
314
314
zend_error (E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
315
315
return & EG (error_zval_ptr );;
@@ -341,8 +341,8 @@ static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object,
341
341
case IS_RESOURCE :
342
342
zend_error (E_STRICT , "Resource ID#%ld used as offset, casting to integer (%ld)" , Z_LVAL_P (offset ), Z_LVAL_P (offset ));
343
343
case IS_DOUBLE :
344
- case IS_BOOL :
345
- case IS_LONG :
344
+ case IS_BOOL :
345
+ case IS_LONG :
346
346
if (offset -> type == IS_DOUBLE ) {
347
347
index = (long )Z_DVAL_P (offset );
348
348
} else {
@@ -386,7 +386,7 @@ static zval *spl_array_read_dimension_ex(int check_inherited, zval *object, zval
386
386
} else {
387
387
SEPARATE_ARG_IF_REF (offset );
388
388
}
389
- zend_call_method_with_1_params (& object , Z_OBJCE_P (object ), & intern -> fptr_offset_get , "offsetGet" , & rv , offset );
389
+ zend_call_method_with_1_params (& object , Z_OBJCE_P (object ), & intern -> fptr_offset_get , "offsetGet" , & rv , offset );
390
390
zval_ptr_dtor (& offset );
391
391
if (rv ) {
392
392
zval_ptr_dtor (& intern -> retval );
@@ -444,7 +444,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval
444
444
zval_ptr_dtor (& offset );
445
445
return ;
446
446
}
447
-
447
+
448
448
if (!offset ) {
449
449
ht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
450
450
if (ht -> nApplyCount > 0 ) {
@@ -467,8 +467,8 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval
467
467
return ;
468
468
case IS_DOUBLE :
469
469
case IS_RESOURCE :
470
- case IS_BOOL :
471
- case IS_LONG :
470
+ case IS_BOOL :
471
+ case IS_LONG :
472
472
ht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
473
473
if (ht -> nApplyCount > 0 ) {
474
474
zend_error (E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
@@ -556,13 +556,13 @@ static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval
556
556
obj -> std .properties_table [property_info -> offset ] = NULL ;
557
557
}
558
558
}
559
- }
559
+ }
560
560
}
561
561
break ;
562
562
case IS_DOUBLE :
563
563
case IS_RESOURCE :
564
- case IS_BOOL :
565
- case IS_LONG :
564
+ case IS_BOOL :
565
+ case IS_LONG :
566
566
if (offset -> type == IS_DOUBLE ) {
567
567
index = (long )Z_DVAL_P (offset );
568
568
} else {
@@ -608,7 +608,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
608
608
}
609
609
return 0 ;
610
610
}
611
-
611
+
612
612
switch (Z_TYPE_P (offset )) {
613
613
case IS_STRING :
614
614
{
@@ -627,9 +627,9 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
627
627
return 0 ;
628
628
case IS_DOUBLE :
629
629
case IS_RESOURCE :
630
- case IS_BOOL :
630
+ case IS_BOOL :
631
631
case IS_LONG :
632
- {
632
+ {
633
633
HashTable * ht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
634
634
if (offset -> type == IS_DOUBLE ) {
635
635
index = (long )Z_DVAL_P (offset );
@@ -727,7 +727,7 @@ void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC) /* {{
727
727
php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
728
728
return ;
729
729
}
730
-
730
+
731
731
if (Z_TYPE_P (intern -> array ) == IS_OBJECT ) {
732
732
php_error_docref (NULL TSRMLS_CC , E_RECOVERABLE_ERROR , "Cannot append properties to objects, use %s::offsetSet() instead" , Z_OBJCE_P (object )-> name );
733
733
return ;
@@ -771,7 +771,7 @@ SPL_METHOD(Array, getArrayCopy)
771
771
{
772
772
zval * object = getThis (), * tmp ;
773
773
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
774
-
774
+
775
775
array_init (return_value );
776
776
zend_hash_copy (HASH_OF (return_value ), spl_array_get_hash_table (intern , 0 TSRMLS_CC ), (copy_ctor_func_t ) zval_add_ref , & tmp , sizeof (zval * ));
777
777
} /* }}} */
@@ -990,7 +990,7 @@ static void spl_array_it_dtor(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
990
990
efree (iterator );
991
991
}
992
992
/* }}} */
993
-
993
+
994
994
static int spl_array_it_valid (zend_object_iterator * iter TSRMLS_DC ) /* {{{ */
995
995
{
996
996
spl_array_it * iterator = (spl_array_it * )iter ;
@@ -1037,7 +1037,7 @@ static int spl_array_it_get_current_key(zend_object_iterator *iter, char **str_k
1037
1037
if (spl_array_object_verify_pos_ex (object , aht , "ArrayIterator::current(): " TSRMLS_CC ) == FAILURE ) {
1038
1038
return HASH_KEY_NON_EXISTANT ;
1039
1039
}
1040
-
1040
+
1041
1041
return zend_hash_get_current_key_ex (aht , str_key , str_key_len , int_key , 1 , & object -> pos );
1042
1042
}
1043
1043
}
@@ -1057,7 +1057,7 @@ static void spl_array_it_move_forward(zend_object_iterator *iter TSRMLS_DC) /* {
1057
1057
php_error_docref (NULL TSRMLS_CC , E_NOTICE , "ArrayIterator::current(): Array was modified outside object and is no longer an array" );
1058
1058
return ;
1059
1059
}
1060
-
1060
+
1061
1061
if ((object -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (object , aht TSRMLS_CC ) == FAILURE ) {
1062
1062
php_error_docref (NULL TSRMLS_CC , E_NOTICE , "ArrayIterator::next(): Array was modified outside object and internal position is no longer valid" );
1063
1063
} else {
@@ -1115,7 +1115,7 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval **a
1115
1115
if (just_array ) {
1116
1116
spl_array_object * other = (spl_array_object * )zend_object_store_get_object (* array TSRMLS_CC );
1117
1117
ar_flags = other -> ar_flags & ~SPL_ARRAY_INT_MASK ;
1118
- }
1118
+ }
1119
1119
ar_flags |= SPL_ARRAY_USE_OTHER ;
1120
1120
intern -> array = * array ;
1121
1121
} else {
@@ -1173,7 +1173,7 @@ zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object,
1173
1173
iterator -> intern .ce = ce ;
1174
1174
iterator -> intern .value = NULL ;
1175
1175
iterator -> object = array_object ;
1176
-
1176
+
1177
1177
return (zend_object_iterator * )iterator ;
1178
1178
}
1179
1179
/* }}} */
@@ -1238,7 +1238,7 @@ SPL_METHOD(Array, getIteratorClass)
1238
1238
{
1239
1239
zval * object = getThis ();
1240
1240
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1241
-
1241
+
1242
1242
if (zend_parse_parameters_none () == FAILURE ) {
1243
1243
return ;
1244
1244
}
@@ -1253,11 +1253,11 @@ SPL_METHOD(Array, getFlags)
1253
1253
{
1254
1254
zval * object = getThis ();
1255
1255
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1256
-
1256
+
1257
1257
if (zend_parse_parameters_none () == FAILURE ) {
1258
1258
return ;
1259
1259
}
1260
-
1260
+
1261
1261
RETURN_LONG (intern -> ar_flags & ~SPL_ARRAY_INT_MASK );
1262
1262
}
1263
1263
/* }}} */
@@ -1273,7 +1273,7 @@ SPL_METHOD(Array, setFlags)
1273
1273
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "l" , & ar_flags ) == FAILURE ) {
1274
1274
return ;
1275
1275
}
1276
-
1276
+
1277
1277
intern -> ar_flags = (intern -> ar_flags & SPL_ARRAY_INT_MASK ) | (ar_flags & ~SPL_ARRAY_INT_MASK );
1278
1278
}
1279
1279
/* }}} */
@@ -1287,7 +1287,7 @@ SPL_METHOD(Array, exchangeArray)
1287
1287
1288
1288
array_init (return_value );
1289
1289
zend_hash_copy (HASH_OF (return_value ), spl_array_get_hash_table (intern , 0 TSRMLS_CC ), (copy_ctor_func_t ) zval_add_ref , & tmp , sizeof (zval * ));
1290
-
1290
+
1291
1291
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "Z" , & array ) == FAILURE ) {
1292
1292
return ;
1293
1293
}
@@ -1305,7 +1305,7 @@ SPL_METHOD(Array, getIterator)
1305
1305
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1306
1306
spl_array_object * iterator ;
1307
1307
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1308
-
1308
+
1309
1309
if (zend_parse_parameters_none () == FAILURE ) {
1310
1310
return ;
1311
1311
}
@@ -1328,7 +1328,7 @@ SPL_METHOD(Array, rewind)
1328
1328
{
1329
1329
zval * object = getThis ();
1330
1330
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1331
-
1331
+
1332
1332
if (zend_parse_parameters_none () == FAILURE ) {
1333
1333
return ;
1334
1334
}
@@ -1361,9 +1361,9 @@ SPL_METHOD(Array, seek)
1361
1361
if (position >= 0 ) { /* negative values are not supported */
1362
1362
spl_array_rewind (intern TSRMLS_CC );
1363
1363
result = SUCCESS ;
1364
-
1364
+
1365
1365
while (position -- > 0 && (result = spl_array_next (intern TSRMLS_CC )) == SUCCESS );
1366
-
1366
+
1367
1367
if (result == SUCCESS && zend_hash_has_more_elements_ex (aht , & intern -> pos ) == SUCCESS ) {
1368
1368
return ; /* ok */
1369
1369
}
@@ -1383,7 +1383,7 @@ int static spl_array_object_count_elements_helper(spl_array_object *intern, long
1383
1383
}
1384
1384
1385
1385
if (Z_TYPE_P (intern -> array ) == IS_OBJECT ) {
1386
- /* We need to store the 'pos' since we'll modify it in the functions
1386
+ /* We need to store the 'pos' since we'll modify it in the functions
1387
1387
* we're going to call and which do not support 'pos' as parameter. */
1388
1388
pos = intern -> pos ;
1389
1389
* count = 0 ;
@@ -1427,7 +1427,7 @@ SPL_METHOD(Array, count)
1427
1427
{
1428
1428
long count ;
1429
1429
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (getThis () TSRMLS_CC );
1430
-
1430
+
1431
1431
if (zend_parse_parameters_none () == FAILURE ) {
1432
1432
return ;
1433
1433
}
@@ -1443,11 +1443,11 @@ static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fnam
1443
1443
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1444
1444
zval * tmp , * arg = NULL ;
1445
1445
zval * retval_ptr = NULL ;
1446
-
1446
+
1447
1447
MAKE_STD_ZVAL (tmp );
1448
1448
Z_TYPE_P (tmp ) = IS_ARRAY ;
1449
1449
Z_ARRVAL_P (tmp ) = aht ;
1450
-
1450
+
1451
1451
if (!use_arg ) {
1452
1452
aht -> nApplyCount ++ ;
1453
1453
zend_call_method (NULL , NULL , NULL , fname , fname_len , & retval_ptr , 1 , tmp , NULL TSRMLS_CC );
@@ -1524,7 +1524,7 @@ SPL_METHOD(Array, current)
1524
1524
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1525
1525
zval * * entry ;
1526
1526
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1527
-
1527
+
1528
1528
if (zend_parse_parameters_none () == FAILURE ) {
1529
1529
return ;
1530
1530
}
@@ -1547,7 +1547,7 @@ SPL_METHOD(Array, key)
1547
1547
if (zend_parse_parameters_none () == FAILURE ) {
1548
1548
return ;
1549
1549
}
1550
-
1550
+
1551
1551
spl_array_iterator_key (getThis (), return_value TSRMLS_CC );
1552
1552
} /* }}} */
1553
1553
@@ -1594,7 +1594,7 @@ SPL_METHOD(Array, next)
1594
1594
1595
1595
spl_array_next_no_verify (intern , aht TSRMLS_CC );
1596
1596
}
1597
- /* }}} */
1597
+ /* }}} */
1598
1598
1599
1599
/* {{{ proto bool ArrayIterator::valid()
1600
1600
Check whether array contains more entries */
@@ -1623,7 +1623,7 @@ SPL_METHOD(Array, hasChildren)
1623
1623
zval * object = getThis (), * * entry ;
1624
1624
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1625
1625
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1626
-
1626
+
1627
1627
if (zend_parse_parameters_none () == FAILURE ) {
1628
1628
return ;
1629
1629
}
@@ -1647,7 +1647,7 @@ SPL_METHOD(Array, getChildren)
1647
1647
zval * object = getThis (), * * entry , * flags ;
1648
1648
spl_array_object * intern = (spl_array_object * )zend_object_store_get_object (object TSRMLS_CC );
1649
1649
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1650
-
1650
+
1651
1651
if (zend_parse_parameters_none () == FAILURE ) {
1652
1652
return ;
1653
1653
}
@@ -1687,7 +1687,7 @@ SPL_METHOD(Array, serialize)
1687
1687
php_serialize_data_t var_hash ;
1688
1688
smart_str buf = {0 };
1689
1689
zval * flags ;
1690
-
1690
+
1691
1691
if (zend_parse_parameters_none () == FAILURE ) {
1692
1692
return ;
1693
1693
}
@@ -1747,7 +1747,7 @@ SPL_METHOD(Array, unserialize)
1747
1747
zval * pmembers , * pflags = NULL ;
1748
1748
HashTable * aht ;
1749
1749
long flags ;
1750
-
1750
+
1751
1751
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & buf , & buf_len ) == FAILURE ) {
1752
1752
return ;
1753
1753
}
@@ -1774,13 +1774,11 @@ SPL_METHOD(Array, unserialize)
1774
1774
1775
1775
ALLOC_INIT_ZVAL (pflags );
1776
1776
if (!php_var_unserialize (& pflags , & p , s + buf_len , & var_hash TSRMLS_CC ) || Z_TYPE_P (pflags ) != IS_LONG ) {
1777
- zval_ptr_dtor (& pflags );
1778
1777
goto outexcept ;
1779
1778
}
1780
1779
1781
1780
-- p ; /* for ';' */
1782
1781
flags = Z_LVAL_P (pflags );
1783
- zval_ptr_dtor (& pflags );
1784
1782
/* flags needs to be verified and we also need to verify whether the next
1785
1783
* thing we get is ';'. After that we require an 'm' or somethign else
1786
1784
* where 'm' stands for members and anything else should be an array. If
@@ -1830,10 +1828,16 @@ SPL_METHOD(Array, unserialize)
1830
1828
/* done reading $serialized */
1831
1829
1832
1830
PHP_VAR_UNSERIALIZE_DESTROY (var_hash );
1831
+ if (pflags ) {
1832
+ zval_ptr_dtor (& pflags );
1833
+ }
1833
1834
return ;
1834
1835
1835
1836
outexcept :
1836
1837
PHP_VAR_UNSERIALIZE_DESTROY (var_hash );
1838
+ if (pflags ) {
1839
+ zval_ptr_dtor (& pflags );
1840
+ }
1837
1841
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 TSRMLS_CC , "Error at offset %ld of %d bytes" , (long )((char * )p - buf ), buf_len );
1838
1842
return ;
1839
1843
@@ -1982,7 +1986,7 @@ PHP_MINIT_FUNCTION(spl_array)
1982
1986
REGISTER_SPL_IMPLEMENTS (ArrayIterator , Countable );
1983
1987
memcpy (& spl_handler_ArrayIterator , & spl_handler_ArrayObject , sizeof (zend_object_handlers ));
1984
1988
spl_ce_ArrayIterator -> get_iterator = spl_array_get_iterator ;
1985
-
1989
+
1986
1990
REGISTER_SPL_SUB_CLASS_EX (RecursiveArrayIterator , ArrayIterator , spl_array_object_new , spl_funcs_RecursiveArrayIterator );
1987
1991
REGISTER_SPL_IMPLEMENTS (RecursiveArrayIterator , RecursiveIterator );
1988
1992
spl_ce_RecursiveArrayIterator -> get_iterator = spl_array_get_iterator ;
0 commit comments