Skip to content

Avoid duplicate code in zend_std_write_property() #14966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
goto exit;
}

typed_property:
ZVAL_COPY_VALUE(&tmp, value);
// Increase refcount to prevent object from being released in __toString()
GC_ADDREF(zobj);
Expand All @@ -977,7 +978,7 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
variable_ptr = &EG(error_zval);
goto exit;
}
Z_PROP_FLAG_P(variable_ptr) &= ~IS_PROP_REINITABLE;
Z_PROP_FLAG_P(variable_ptr) &= ~(IS_PROP_UNINIT|IS_PROP_REINITABLE);
value = &tmp;
}

Expand Down Expand Up @@ -1105,25 +1106,7 @@ found:;
variable_ptr = &EG(error_zval);
goto exit;
}

ZVAL_COPY_VALUE(&tmp, value);
// Increase refcount to prevent object from being released in __toString()
GC_ADDREF(zobj);
bool type_matched = zend_verify_property_type(prop_info, &tmp, property_uses_strict_types());
if (UNEXPECTED(GC_DELREF(zobj) == 0)) {
zend_object_released_while_assigning_to_property_error(prop_info);
zend_objects_store_del(zobj);
zval_ptr_dtor(&tmp);
variable_ptr = &EG(error_zval);
goto exit;
}
if (UNEXPECTED(!type_matched)) {
zval_ptr_dtor(value);
goto exit;
}
value = &tmp;
Z_PROP_FLAG_P(variable_ptr) = 0;
goto found; /* might have been updated via e.g. __toString() */
goto typed_property;
}

ZVAL_COPY_VALUE(variable_ptr, value);
Expand Down
Loading