From: Anatol Belski Date: Tue, 14 Aug 2018 12:14:05 +0000 (+0200) Subject: Followup fix for ef9ed19e, see also bug #76738 X-Git-Tag: php-7.3.0beta3~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddd73d4fa8155f8fa8d0d29082136d5719afd1f4;p=php Followup fix for ef9ed19e, see also bug #76738 (cherry picked from commit 083285f22a74989689f97d1d53476e7eaec35acc) --- diff --git a/ext/dom/document.c b/ext/dom/document.c index 6bbc0500b9..e16788072b 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -2152,7 +2152,7 @@ PHP_FUNCTION(dom_document_save_html) xmlBufferPtr buf; dom_object *intern, *nodeobj; xmlChar *mem = NULL; - int size = 0, format; + int format; dom_doc_propsptr doc_props; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), @@ -2182,39 +2182,26 @@ PHP_FUNCTION(dom_document_save_html) } if (node->type == XML_DOCUMENT_FRAG_NODE) { - int one_size; - for (node = node->children; node; node = node->next) { htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format); -#ifdef LIBXML2_NEW_BUFFER - one_size = !outBuf->error ? xmlOutputBufferGetSize(outBuf) : -1; -#else - one_size = !outBuf->error ? outBuf->buffer->use : -1; -#endif - if (one_size >= 0) { - size = one_size; - } else { - size = -1; + if (outBuf->error) { break; } } } else { htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format); -#ifdef LIBXML2_NEW_BUFFER - size = !outBuf->error ? xmlOutputBufferGetSize(outBuf): -1; -#else - size = !outBuf->error ? outBuf->buffer->use : -1; -#endif } - if (size >= 0) { + if (!outBuf->error) { + xmlOutputBufferFlush(outBuf); #ifdef LIBXML2_NEW_BUFFER - mem = (xmlChar*) xmlOutputBufferGetContent(outBuf); + mem = (xmlChar*) xmlBufferContent(buf); #else mem = (xmlChar*) outBuf->buffer->content; #endif if (!mem) { RETVAL_FALSE; } else { + int size = xmlBufferLength(buf); RETVAL_STRINGL((const char*) mem, size); } } else { @@ -2223,6 +2210,7 @@ PHP_FUNCTION(dom_document_save_html) } xmlOutputBufferClose(outBuf); } else { + int size = 0; #if LIBXML_VERSION >= 20623 htmlDocDumpMemoryFormat(docp, &mem, &size, format); #else