From c1c4d2681782772d41ba68f32eb71baa907e10de Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 19 Feb 2014 17:58:39 +0800 Subject: [PATCH 1/2] Use better data structures (incomplete) --- ext/date/php_date.c | 7 +++---- ext/spl/spl_heap.c | 4 ++-- sapi/phpdbg/phpdbg_info.c | 6 +++--- sapi/phpdbg/phpdbg_list.c | 2 +- sapi/phpdbg/phpdbg_print.c | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 19895ee7e62..05dccf4f8e8 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4215,14 +4215,14 @@ PHP_FUNCTION(date_interval_create_from_date_string) /* }}} */ /* {{{ date_interval_format - */ -static char *date_interval_format(char *format, int format_len, timelib_rel_time *t) +static zend_string *date_interval_format(char *format, int format_len, timelib_rel_time *t) { smart_str string = {0}; int i, length, have_format_spec = 0; char buffer[33]; if (!format_len) { - return estrdup(""); + return STR_EMPTY_ALLOC(); } for (i = 0; i < format_len; i++) { @@ -4292,8 +4292,7 @@ PHP_FUNCTION(date_interval_format) diobj = (php_interval_obj *) Z_OBJ_P(object); DATE_CHECK_INITIALIZED(diobj->initialized, DateInterval); -//??? RETURN_STRING(date_interval_format(format, format_len, diobj->diff), 0); - RETURN_STRING(date_interval_format(format, format_len, diobj->diff)); + RETURN_STR(date_interval_format(format, format_len, diobj->diff)); } /* }}} */ diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index 45b50c2d25e..91590007994 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -896,7 +896,7 @@ static zval *spl_heap_it_get_current_data(zend_object_iterator *iter TSRMLS_DC) if (iterator->object->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC); - return; + return NULL; } if (iterator->object->heap->count == 0 || ZVAL_IS_UNDEF(element)) { @@ -914,7 +914,7 @@ static zval *spl_pqueue_it_get_current_data(zend_object_iterator *iter TSRMLS_DC if (iterator->object->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0 TSRMLS_CC); - return; + return NULL; } if (iterator->object->heap->count == 0 || ZVAL_IS_UNDEF(element)) { diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c index 281cfc406a8..d1a3cf6a9b0 100644 --- a/sapi/phpdbg/phpdbg_info.c +++ b/sapi/phpdbg/phpdbg_info.c @@ -196,15 +196,15 @@ PHPDBG_INFO(literal) /* {{{ */ if (ops->function_name) { if (ops->scope) { phpdbg_notice( - "Literal Constants in %s::%s() (%d)", ops->scope->name, ops->function_name, count); + "Literal Constants in %s::%s() (%d)", ops->scope->name, ops->function_name->val, count); } else { phpdbg_notice( - "Literal Constants in %s() (%d)", ops->function_name, count); + "Literal Constants in %s() (%d)", ops->function_name->val, count); } } else { if (ops->filename) { phpdbg_notice( - "Literal Constants in %s (%d)", ops->filename, count); + "Literal Constants in %s (%d)", ops->filename->val, count); } else { phpdbg_notice( "Literal Constants @ %p (%d)", ops, count); diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c index 4ef3db98ea6..68352ac7635 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -238,7 +238,7 @@ void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */ const zend_op_array *ops; if (fbc->type != ZEND_USER_FUNCTION) { - phpdbg_error("The function requested (%s) is not user defined", fbc->common.function_name); + phpdbg_error("The function requested (%s) is not user defined", fbc->common.function_name->val); return; } diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 8836eed1374..131862ceb8d 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -155,7 +155,7 @@ PHPDBG_PRINT(class) /* {{{ */ (ce->ce_flags & ZEND_ACC_ABSTRACT) ? "Abstract Class" : "Class", - *ce->name->val); + ce->name->val); phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&ce->function_table)); if (zend_hash_num_elements(&ce->function_table)) { @@ -197,7 +197,7 @@ PHPDBG_PRINT(method) /* {{{ */ if ((fbc = zend_hash_str_find_ptr(&ce->function_table, lcname, strlen(lcname))) != NULL) { phpdbg_notice("%s Method %s", (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal", - fbc->common.function_name); + fbc->common.function_name->val); phpdbg_print_function_helper(fbc TSRMLS_CC); } else { From 757facf6c184093734ddfd0c2f28e84bc9f9b6ee Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 19 Feb 2014 18:34:27 +0800 Subject: [PATCH 2/2] Fixed segfault in BEGIN/END SILENT --- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 58dcb48ce83..0a9d86490d8 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -4676,7 +4676,7 @@ ZEND_VM_HANDLER(58, ZEND_END_SILENCE, TMP, ANY) EG(error_reporting_ini_entry)->value != EG(error_reporting_ini_entry)->orig_value)) { efree(EG(error_reporting_ini_entry)->value); } - EG(error_reporting_ini_entry)->value = Z_STRVAL(restored_error_reporting); + EG(error_reporting_ini_entry)->value = estrndup(Z_STRVAL(restored_error_reporting), Z_STRLEN(restored_error_reporting)); EG(error_reporting_ini_entry)->value_length = Z_STRLEN(restored_error_reporting); } else { zval_dtor(&restored_error_reporting); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index cd0395c6c61..7505189e51a 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -8100,7 +8100,7 @@ static int ZEND_FASTCALL ZEND_END_SILENCE_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ EG(error_reporting_ini_entry)->value != EG(error_reporting_ini_entry)->orig_value)) { efree(EG(error_reporting_ini_entry)->value); } - EG(error_reporting_ini_entry)->value = Z_STRVAL(restored_error_reporting); + EG(error_reporting_ini_entry)->value = estrndup(Z_STRVAL(restored_error_reporting), Z_STRLEN(restored_error_reporting)); EG(error_reporting_ini_entry)->value_length = Z_STRLEN(restored_error_reporting); } else { zval_dtor(&restored_error_reporting);