Skip to content

Commit ddd73d4

Browse files
weltlingcmb69
authored andcommitted
Followup fix for ef9ed19, see also bug #76738
(cherry picked from commit 083285f)
1 parent 10d724d commit ddd73d4

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

ext/dom/document.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ PHP_FUNCTION(dom_document_save_html)
21522152
xmlBufferPtr buf;
21532153
dom_object *intern, *nodeobj;
21542154
xmlChar *mem = NULL;
2155-
int size = 0, format;
2155+
int format;
21562156
dom_doc_propsptr doc_props;
21572157

21582158
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
@@ -2182,39 +2182,26 @@ PHP_FUNCTION(dom_document_save_html)
21822182
}
21832183

21842184
if (node->type == XML_DOCUMENT_FRAG_NODE) {
2185-
int one_size;
2186-
21872185
for (node = node->children; node; node = node->next) {
21882186
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
2189-
#ifdef LIBXML2_NEW_BUFFER
2190-
one_size = !outBuf->error ? xmlOutputBufferGetSize(outBuf) : -1;
2191-
#else
2192-
one_size = !outBuf->error ? outBuf->buffer->use : -1;
2193-
#endif
2194-
if (one_size >= 0) {
2195-
size = one_size;
2196-
} else {
2197-
size = -1;
2187+
if (outBuf->error) {
21982188
break;
21992189
}
22002190
}
22012191
} else {
22022192
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
2203-
#ifdef LIBXML2_NEW_BUFFER
2204-
size = !outBuf->error ? xmlOutputBufferGetSize(outBuf): -1;
2205-
#else
2206-
size = !outBuf->error ? outBuf->buffer->use : -1;
2207-
#endif
22082193
}
2209-
if (size >= 0) {
2194+
if (!outBuf->error) {
2195+
xmlOutputBufferFlush(outBuf);
22102196
#ifdef LIBXML2_NEW_BUFFER
2211-
mem = (xmlChar*) xmlOutputBufferGetContent(outBuf);
2197+
mem = (xmlChar*) xmlBufferContent(buf);
22122198
#else
22132199
mem = (xmlChar*) outBuf->buffer->content;
22142200
#endif
22152201
if (!mem) {
22162202
RETVAL_FALSE;
22172203
} else {
2204+
int size = xmlBufferLength(buf);
22182205
RETVAL_STRINGL((const char*) mem, size);
22192206
}
22202207
} else {
@@ -2223,6 +2210,7 @@ PHP_FUNCTION(dom_document_save_html)
22232210
}
22242211
xmlOutputBufferClose(outBuf);
22252212
} else {
2213+
int size = 0;
22262214
#if LIBXML_VERSION >= 20623
22272215
htmlDocDumpMemoryFormat(docp, &mem, &size, format);
22282216
#else

0 commit comments

Comments
 (0)