Skip to content

Commit

Permalink
fixed a problem occuring only in x86_64 when very large error message…
Browse files Browse the repository at this point in the history
…s are

* python/libxml.c: fixed a problem occuring only in x86_64 when
  very large error messages are raied to the Python handlers.
Daniel
  • Loading branch information
Daniel Veillard committed Oct 22, 2004
1 parent 1a380b8 commit ad9fb7c
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 273 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Fri Oct 22 21:04:20 CEST 2004 Daniel Veillard <[email protected]>

* python/libxml.c: fixed a problem occuring only in x86_64 when
very large error messages are raied to the Python handlers.

Thu Oct 21 18:03:21 CEST 2004 Daniel Veillard <[email protected]>

* xmlschemas.c: fixed a memory bug
Expand Down
5 changes: 4 additions & 1 deletion config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Define if compiler has function prototypes */
/* Define to 1 if the C compiler supports function prototypes. */
#undef PROTOTYPES

/* Determine what socket length (socklen_t) data type is */
Expand All @@ -273,6 +273,9 @@
/* Using the Win32 Socket implementation */
#undef _WINSOCKAPI_

/* Define like PROTOTYPES; this can be used by system headers. */
#undef __PROTOTYPES

/* Win32 Std C name mangling work-around */
#undef snprintf

Expand Down
35 changes: 13 additions & 22 deletions python/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1427,34 +1427,24 @@ static PyObject *libxml_xmlPythonErrorFuncHandler = NULL;
static PyObject *libxml_xmlPythonErrorFuncCtxt = NULL;

/* helper to build a xmlMalloc'ed string from a format and va_list */
/*
* disabled the loop, the repeated call to vsnprintf without reset of ap
* in case the initial buffer was too small segfaulted on x86_64
* we now directly vsnprintf on a large buffer.
*/
static char *
libxml_buildMessage(const char *msg, va_list ap)
{
int size;
int chars;
char *larger;
char *str;

str = (char *) xmlMalloc(150);
str = (char *) xmlMalloc(1000);
if (str == NULL)
return NULL;

size = 150;

while (1) {
chars = vsnprintf(str, size, msg, ap);
if ((chars > -1) && (chars < size))
break;
if (chars > -1)
size += chars + 1;
else
size += 100;
if ((larger = (char *) xmlRealloc(str, size)) == NULL) {
xmlFree(str);
return NULL;
}
str = larger;
}
chars = vsnprintf(str, 999, msg, ap);
if (chars >= 998)
str[999] = 0;

return str;
}
Expand All @@ -1464,10 +1454,10 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
...)
{
va_list ap;
char *str;
PyObject *list;
PyObject *message;
PyObject *result;
char str[1000];

#ifdef DEBUG_ERROR
printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
Expand All @@ -1480,13 +1470,14 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
va_end(ap);
} else {
va_start(ap, msg);
str = libxml_buildMessage(msg,ap);
if (vsnprintf(str, 999, msg, ap) >= 998)
str[999] = 0;
va_end(ap);

list = PyTuple_New(2);
PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
message = libxml_charPtrWrap(str);
message = libxml_charPtrConstWrap(str);
PyTuple_SetItem(list, 1, message);
result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
Py_XDECREF(list);
Expand Down
Loading

0 comments on commit ad9fb7c

Please sign in to comment.