From: Xinchen Hui Date: Sat, 28 Oct 2017 13:38:26 +0000 (+0800) Subject: Fixed bug #75451 (Assertion fails while foreach on empty xpath query) X-Git-Tag: php-7.3.0alpha1~1159^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a9e64362cdfc6911ecda32d507dab0994909e0a;p=php Fixed bug #75451 (Assertion fails while foreach on empty xpath query) --- diff --git a/ext/dom/tests/bug75451.phpt b/ext/dom/tests/bug75451.phpt new file mode 100644 index 0000000000..dae7cde98b --- /dev/null +++ b/ext/dom/tests/bug75451.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #75451 (Assertion fails while foreach on empty xpath query) +--SKIPIF-- + +--FILE-- +loadXML(''); +$xpath = new DOMXpath($dom); +foreach($xpath->query('/root/noexist') as $child) { + var_dump($child); +} +?> +okey +--EXPECT-- +okey diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index f0b908ccf3..31e4dc98b4 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -432,9 +432,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ int i; xmlNodeSetPtr nodesetp; + array_init(&retval); if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) { - - array_init(&retval); for (i = 0; i < nodesetp->nodeNr; i++) { xmlNodePtr node = nodesetp->nodeTab[i]; zval child; @@ -460,8 +459,6 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ php_dom_create_object(node, &child, &intern->dom); add_next_index_zval(&retval, &child); } - } else { - ZVAL_EMPTY_ARRAY(&retval); } php_dom_create_interator(return_value, DOM_NODELIST); nodeobj = Z_DOMOBJ_P(return_value);