diff options
Diffstat (limited to 'Source/WebCore/xml')
-rw-r--r-- | Source/WebCore/xml/XSLTUnicodeSort.cpp | 16 | ||||
-rw-r--r-- | Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp | 23 |
2 files changed, 20 insertions, 19 deletions
diff --git a/Source/WebCore/xml/XSLTUnicodeSort.cpp b/Source/WebCore/xml/XSLTUnicodeSort.cpp index 54d5abd10..def0f9482 100644 --- a/Source/WebCore/xml/XSLTUnicodeSort.cpp +++ b/Source/WebCore/xml/XSLTUnicodeSort.cpp @@ -33,6 +33,8 @@ #include <libxslt/templates.h> #include <libxslt/xsltutils.h> +#include <wtf/StringExtras.h> +#include <wtf/Vector.h> #include <wtf/unicode/Collator.h> #if OS(DARWIN) && !PLATFORM(EFL) && !PLATFORM(GTK) && !PLATFORM(QT) @@ -51,15 +53,19 @@ void xsltTransformErrorTrampoline(xsltTransformContextPtr context, xsltStyleshee { va_list args; va_start(args, message); - char* messageWithArgs; - vasprintf(&messageWithArgs, message, args); + + va_list preflightArgs; + va_copy(preflightArgs, args); + size_t stringLength = vsnprintf(nullptr, 0, message, preflightArgs); + va_end(preflightArgs); + + Vector<char, 1024> buffer(stringLength + 1); + vsnprintf(buffer.data(), stringLength + 1, message, args); va_end(args); static void (*xsltTransformErrorPointer)(xsltTransformContextPtr, xsltStylesheetPtr, xmlNodePtr, const char*, ...) WTF_ATTRIBUTE_PRINTF(4, 5) = reinterpret_cast<void (*)(xsltTransformContextPtr, xsltStylesheetPtr, xmlNodePtr, const char*, ...)>(dlsym(libxsltLibrary(), "xsltTransformError")); - xsltTransformErrorPointer(context, style, node, "%s", messageWithArgs); - - free(messageWithArgs); + xsltTransformErrorPointer(context, style, node, "%s", buffer.data()); } #define xsltTransformError xsltTransformErrorTrampoline diff --git a/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp b/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp index 0e77eac4d..0bcdc4c92 100644 --- a/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp +++ b/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp @@ -963,24 +963,19 @@ void XMLDocumentParser::error(XMLErrors::ErrorType type, const char* message, va if (isStopped()) return; -#if HAVE(VASPRINTF) - char* m; - if (vasprintf(&m, message, args) == -1) - return; -#else - char m[1024]; - vsnprintf(m, sizeof(m) - 1, message, args); -#endif + va_list preflightArgs; + va_copy(preflightArgs, args); + size_t stringLength = vsnprintf(nullptr, 0, message, preflightArgs); + va_end(preflightArgs); + + Vector<char, 1024> buffer(stringLength + 1); + vsnprintf(buffer.data(), stringLength + 1, message, args); TextPosition position = textPosition(); if (m_parserPaused) - m_pendingCallbacks->appendErrorCallback(type, reinterpret_cast<const xmlChar*>(m), position.m_line, position.m_column); + m_pendingCallbacks->appendErrorCallback(type, reinterpret_cast<const xmlChar*>(buffer.data()), position.m_line, position.m_column); else - handleError(type, m, textPosition()); - -#if HAVE(VASPRINTF) - free(m); -#endif + handleError(type, buffer.data(), textPosition()); } void XMLDocumentParser::processingInstruction(const xmlChar* target, const xmlChar* data) |