diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-11-09 17:59:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-11-09 17:59:14 +0300 |
commit | db1e60556c72b1b87ff2a384c556ccca724c46d6 (patch) | |
tree | 22a5f4e9c4f436ef8e746e0a2d688de80c1597a6 /src/utils/xml.cpp | |
parent | c2bb49be52a92deccec7428b6859242688fc8987 (diff) | |
parent | 1716861f0ee2f7a3714c5b44bb0f017c3d8d3b2c (diff) | |
download | plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.tar.gz plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.tar.bz2 plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.tar.xz plus-db1e60556c72b1b87ff2a384c556ccca724c46d6.zip |
Merge branch 'master' into stable
Diffstat (limited to 'src/utils/xml.cpp')
-rw-r--r-- | src/utils/xml.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 5f691fd68..b87418079 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -34,9 +34,39 @@ #include "debug.h" -static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) +static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...) +#ifdef __GNUC__ +#ifdef __OpenBSD__ + __attribute__((__format__(printf, 2, 3))) +#else + __attribute__((__format__(gnu_printf, 2, 3))) +#endif +#endif +; + +static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg, ...) { - // Does nothing, that's the whole point of it + unsigned size = 1024; + const unsigned msgSize = strlen(msg); + if (msgSize * 3 > size) + size = static_cast<unsigned>(msgSize * 3); + + char* buf = new char[size + 1]; + va_list ap; + + // Use a temporary buffer to fill in the variables + va_start(ap, msg); + vsnprintf(buf, size, msg, ap); + buf[size] = 0; + va_end(ap); + + if (logger) + logger->log1(buf); + else + puts(buf); + + // Delete temporary buffer + delete [] buf; } namespace XML @@ -213,7 +243,7 @@ namespace XML LIBXML_TEST_VERSION; // Suppress libxml2 error messages - xmlSetGenericErrorFunc(nullptr, &xmlNullLogger); + xmlSetGenericErrorFunc(nullptr, &xmlErrorLogger); } // Shutdown libxml |