Skip to content

Commit

Permalink
Simplify change_node_zval implementation
Browse files Browse the repository at this point in the history
At this point, the value has already been converted into a string.
  • Loading branch information
nikic committed Aug 25, 2020
1 parent d384537 commit afde6dc
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,31 +377,12 @@ static zval *sxe_dimension_read(zend_object *object, zval *offset, int type, zva
static void change_node_zval(xmlNodePtr node, zval *value)
{
xmlChar *buffer;

if (!value)
{
xmlNodeSetContentLen(node, (xmlChar *)"", 0);
return;
}
switch (Z_TYPE_P(value)) {
case IS_LONG:
case IS_FALSE:
case IS_TRUE:
case IS_DOUBLE:
case IS_NULL:
convert_to_string(value);
/* break missing intentionally */
case IS_STRING:
buffer = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)Z_STRVAL_P(value));
/* check for NULL buffer in case of memory error in xmlEncodeEntitiesReentrant */
if (buffer) {
xmlNodeSetContent(node, buffer);
xmlFree(buffer);
}
break;
default:
php_error_docref(NULL, E_WARNING, "It is not possible to assign complex types to nodes");
break;
ZEND_ASSERT(Z_TYPE_P(value) == IS_STRING);
buffer = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)Z_STRVAL_P(value));
/* check for NULL buffer in case of memory error in xmlEncodeEntitiesReentrant */
if (buffer) {
xmlNodeSetContent(node, buffer);
xmlFree(buffer);
}
}
/* }}} */
Expand Down

0 comments on commit afde6dc

Please sign in to comment.