From 8c2c69494e65d16193d60580a1c6bf7f474ed175 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 8 Sep 2023 22:51:22 +0200 Subject: [PATCH] Replace always-false attribute type check with assertion The type will always be XML_ATTRIBUTE_NODE by construction via php_dom_create_object, no need to check the type. Use an assertion instead. This simplifies code and reasoning about error conditions. --- ext/dom/element.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ext/dom/element.c b/ext/dom/element.c index 8a19a49c1a6..b009ca1d771 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -520,10 +520,7 @@ PHP_METHOD(DOMElement, setAttributeNode) DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj); - if (attrp->type != XML_ATTRIBUTE_NODE) { - zend_argument_value_error(1, "must have the node attribute"); - RETURN_THROWS(); - } + ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE); if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) { php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document)); @@ -581,7 +578,9 @@ PHP_METHOD(DOMElement, removeAttributeNode) DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj); - if (attrp->type != XML_ATTRIBUTE_NODE || attrp->parent != nodep) { + ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE); + + if (attrp->parent != nodep) { php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document)); RETURN_FALSE; }