diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2008-09-25 14:55:21 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2008-09-25 14:55:21 +0000 |
commit | 7e65fad1e3a60c2a550a046ac58d99bc06760a77 (patch) | |
tree | 4da04872fee707b3be0a826e071a60c19d355464 | |
parent | 856d92818bda07549a532d6fb16f323a94e0c39a (diff) | |
download | libxml2-7e65fad1e3a60c2a550a046ac58d99bc06760a77.tar.gz |
patch from Riccardo Scussat fixing custom error handlers problems. daniel
* xmlreader.c: patch from Riccardo Scussat fixing custom error
handlers problems.
daniel
svn path=/trunk/; revision=3795
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | xmlreader.c | 57 |
2 files changed, 45 insertions, 17 deletions
@@ -1,3 +1,8 @@ +Thu Sep 25 16:54:04 CEST 2008 Daniel Veillard <daniel@veillard.com> + + * xmlreader.c: patch from Riccardo Scussat fixing custom error + handlers problems. + Thu Sep 25 16:30:11 CEST 2008 Daniel Veillard <daniel@veillard.com> * include/libxml/xmlsave.h xmlsave.c: new options to serialize diff --git a/xmlreader.c b/xmlreader.c index bd47ea51..d42b1a0c 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -44,6 +44,27 @@ #include <libxml/pattern.h> #endif +#define MAX_ERR_MSG_SIZE 64000 + +/* + * The following VA_COPY was coded following an example in + * the Samba project. It may not be sufficient for some + * esoteric implementations of va_list (i.e. it may need + * something involving a memcpy) but (hopefully) will be + * sufficient for libxml2. + */ +#ifndef VA_COPY + #ifdef HAVE_VA_COPY + #define VA_COPY(dest, src) va_copy(dest, src) + #else + #ifdef HAVE___VA_COPY + #define VA_COPY(dest,src) __va_copy(dest, src) + #else + #define VA_COPY(dest,src) (dest) = (src) + #endif + #endif +#endif + /* #define DEBUG_CALLBACKS */ /* #define DEBUG_READER */ @@ -4500,30 +4521,32 @@ xmlTextReaderStandalone(xmlTextReaderPtr reader) { /* helper to build a xmlMalloc'ed string from a format and va_list */ static char * xmlTextReaderBuildMessage(const char *msg, va_list ap) { - int size; + int size = 0; int chars; char *larger; - char *str; - - str = (char *) xmlMallocAtomic(150); - if (str == NULL) { - xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n"); - return NULL; - } - - size = 150; + char *str = NULL; + va_list aq; while (1) { - chars = vsnprintf(str, size, msg, ap); - if ((chars > -1) && (chars < size)) + VA_COPY(aq, ap); + chars = vsnprintf(str, size, msg, aq); + va_end(aq); + if (chars < 0) { + xmlGenericError(xmlGenericErrorContext, "vsnprintf failed !\n"); + if (str) + xmlFree(str); + return NULL; + } + if ((chars < size) || (size == MAX_ERR_MSG_SIZE)) break; - if (chars > -1) - size += chars + 1; - else - size += 100; + if (chars < MAX_ERR_MSG_SIZE) + size = chars + 1; + else + size = MAX_ERR_MSG_SIZE; if ((larger = (char *) xmlRealloc(str, size)) == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlRealloc failed !\n"); - xmlFree(str); + if (str) + xmlFree(str); return NULL; } str = larger; |