]> granicus.if.org Git - php/commitdiff
Followup fix for ef9ed19e, see also bug #76738
authorAnatol Belski <ab@php.net>
Tue, 14 Aug 2018 12:14:05 +0000 (14:14 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 17 Aug 2018 11:01:56 +0000 (13:01 +0200)
(cherry picked from commit 083285f22a74989689f97d1d53476e7eaec35acc)

ext/dom/document.c

index 6bbc0500b91346ce6bad658a0a351bf96129a0f0..e16788072b556b3997963839fe95136540058241 100644 (file)
@@ -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