summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2003-02-16 19:18:23 +0000
committerZeev Suraski <zeev@php.net>2003-02-16 19:18:23 +0000
commitac0f7d9ed0b9254f8980b81822e6e75af40bb414 (patch)
treeaf3844014fc079d5a11a091fc4ea8ce85cae0dfd
parentf079bb65ff65e9ea35703add37f61279a5590c0c (diff)
downloadphp-git-ac0f7d9ed0b9254f8980b81822e6e75af40bb414.tar.gz
Fix complex cases of self-assignments (bugs #21600, #22231)
-rw-r--r--Zend/zend_execute.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 8c94d0b1db..3f1c52e82b 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -196,8 +196,7 @@ void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, z
if (variable_ptr == EG(error_zval_ptr) || value_ptr==EG(error_zval_ptr)) {
variable_ptr_ptr = &EG(uninitialized_zval_ptr);
-/* } else if (variable_ptr==&EG(uninitialized_zval) || variable_ptr!=value_ptr) { */
- } else if (variable_ptr_ptr != value_ptr_ptr) {
+ } else if (variable_ptr != value_ptr) {
variable_ptr->refcount--;
if (variable_ptr->refcount==0) {
zendi_zval_dtor(*variable_ptr);
@@ -219,9 +218,18 @@ void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, z
*variable_ptr_ptr = value_ptr;
value_ptr->refcount++;
- } else {
- if (variable_ptr->refcount>1) { /* we need to break away */
+ } else if (!variable_ptr->is_ref) {
+ if (variable_ptr_ptr == value_ptr_ptr) {
SEPARATE_ZVAL(variable_ptr_ptr);
+ } else if (variable_ptr==EG(uninitialized_zval_ptr)
+ || variable_ptr->refcount>2) {
+ /* we need to separate */
+ variable_ptr->refcount -= 2;
+ ALLOC_ZVAL(*variable_ptr_ptr);
+ **variable_ptr_ptr = *variable_ptr;
+ zval_copy_ctor(*variable_ptr_ptr);
+ *value_ptr_ptr = *variable_ptr_ptr;
+ (*variable_ptr_ptr)->refcount = 2;
}
(*variable_ptr_ptr)->is_ref = 1;
}