mirror of
https://github.com/php/php-src.git
synced 2026-03-26 17:22:15 +01:00
Fixed var_dump() crash when there is recursion.
# Since I said it's easy to fix :)
This commit is contained in:
@@ -60,6 +60,7 @@ static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_ha
|
||||
void php_var_dump(zval **struc, int level TSRMLS_DC)
|
||||
{
|
||||
HashTable *myht;
|
||||
zend_object *object = NULL;
|
||||
|
||||
if (level > 1) {
|
||||
php_printf("%*c", level - 1, ' ');
|
||||
@@ -85,13 +86,31 @@ void php_var_dump(zval **struc, int level TSRMLS_DC)
|
||||
break;
|
||||
case IS_ARRAY:
|
||||
myht = Z_ARRVAL_PP(struc);
|
||||
if (++((*struc)->value.ht->nApplyCount) > 1) {
|
||||
PUTS("*RECURSION*\n");
|
||||
(*struc)->value.ht->nApplyCount = 0;
|
||||
break;
|
||||
}
|
||||
php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht));
|
||||
goto head_done;
|
||||
case IS_OBJECT:
|
||||
object = Z_OBJ_PP(struc);
|
||||
if (++object->properties->nApplyCount > 1) {
|
||||
PUTS("*RECURSION*\n");
|
||||
object->properties->nApplyCount = 0;
|
||||
return;
|
||||
}
|
||||
myht = Z_OBJPROP_PP(struc);
|
||||
php_printf("%sobject(%s)(%d) {\n", COMMON, Z_OBJCE_PP(struc)->name, zend_hash_num_elements(myht));
|
||||
head_done:
|
||||
myht = Z_ARRVAL_PP(struc);
|
||||
zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level);
|
||||
if (Z_TYPE_PP(struc) == IS_ARRAY) {
|
||||
(*struc)->value.ht->nApplyCount--;
|
||||
}
|
||||
else {
|
||||
object->properties->nApplyCount--;
|
||||
}
|
||||
if (level > 1) {
|
||||
php_printf("%*c", level-1, ' ');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user