Hi,
We saw some test failures running the python tests for libxml-2.7.8 that
turned out to be related to libc's vsnprintf being buggy.
Unfortunately, though vsnprintf(buf,len,format,ap) should return the number
of chars that would have been written to buf (not including the final
NULL), not all systems see it that way.
For example, with a string that ends up being 7 chars long we get these
return values for different values of 'len':
OS \ len 4 1 0
+---------+-------+-----+-----+-----+
|Solaris 6-9 | 7 | 7 | -1 |
|Solaris 10 | 7 | 7 | 7 |
|HPUX 10.20-11.23 | -1 | -1 | 7 |
|HPUX 11.31 | -1 | -1 | 0 |
|AIX 5.1 | 7 | 7 | 0 |
|AIX 5.2-7.1 | 7 | 7 | 7 |
|Tru64 5.1 | 3 | 0 | 0 |
|SGI IRIX 6.5 | 3 | 0 | -1 |
|Linux/Glibc | 7 | 7 | 7 |
+-----------------+-----+-----+-----+
On Tru64 and IRIX vsnprintf returns the # of chars it actually copied,
on HP-UX it usually just returns -1 if len isn't long enough. To make
matters worse, if buf is NULL, it causes sigsegv or sigbus on HP-UX <
11.31, AIX 5.1 and Tru64.
While it is possible to check in configure how the system's stdio
implementation is broken, it seems easier to use libxml's included trio.
Trio's vsnprintf doesn't like NULL buffers either, so we avoid doing
that.
Hack attached
Peter
--
Peter O'Gorman
[email protected]
diff --git a/Makefile.am b/Makefile.am
index b8cbb4a..2cd345b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,17 +31,6 @@ libxml2_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@
@WIN32_EXTRA_LDFLAGS@ \
-version-info @LIBXML_VERSION_INFO@ \
@MODULE_PLATFORM_LIBS@
-if WITH_TRIO_SOURCES
-libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
- parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
- valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
- xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
- catalog.c globals.c threads.c c14n.c xmlstring.c \
- xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
- triostr.c trio.c xmlreader.c relaxng.c dict.c SAX2.c \
- xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \
- xmlmodule.c schematron.c
-else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
@@ -51,6 +40,8 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c
parserInternals.c \
xmlreader.c relaxng.c dict.c SAX2.c \
xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \
xmlmodule.c schematron.c
+if WITH_TRIO_SOURCES
+libxml2_la_SOURCES += trio.c triostr.c
endif
DEPS = $(top_builddir)/libxml2.la
diff --git a/configure.in b/configure.in
index a1d2c89..346b7df 100644
--- a/configure.in
+++ b/configure.in
@@ -479,6 +479,25 @@ AC_CHECK_FUNCS(stat _stat signal)
dnl Checking the standard string functions availability
AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf
sscanf,,
NEED_TRIO=1)
+AC_CACHE_CHECK([if vsnprintf is POSIX compliant],[xml_cv_working_vsnprintf],
+[xml_cv_working_vsnprintf=yes
+AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
+#include <stdarg.h>
+static int printit(const char *format, ...) {
+int retcode = 0;
+va_list ap;
+char buf[2];
+va_start(ap,format);
+retcode = vsnprintf(buf,1,format,ap);
+va_end(ap);
+return retcode;
+}]],[
+return printit("%s","hello") != 5;
+])],,[xml_cv_working_vsnprintf=no])])
+if test "X$xml_cv_working_vsnprintf" = "Xno"; then
+ NEED_TRIO=1
+ AC_DEFINE([BROKEN_VSNPRINTF],[1],[if vsnprintf does not work properly])
+fi
dnl Checking for va_copy availability
AC_MSG_CHECKING([for va_copy])
diff --git a/xmlreader.c b/xmlreader.c
index 97c71ab..1a491d2 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -4545,6 +4545,11 @@ xmlTextReaderBuildMessage(const char *msg, va_list ap) {
char *str = NULL;
va_list aq;
+ /* While it should work to call vsnprintf(NULL, it does not work
+ * on Solaris < 10, HP-UX, AIX 5.1, IRIX, or Tru64 Unix, so we
+ * allocate a string to start with */
+ size = 64;
+ str = xmlMalloc(size);
while (1) {
VA_COPY(aq, ap);
chars = vsnprintf(str, size, msg, aq);
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml