[LIBXML2] Update to version 2.9.7. CORE-14291

This commit is contained in:
Thomas Faber 2018-02-04 17:15:47 +01:00
parent b97f0a8fed
commit fc82f8e2e3
No known key found for this signature in database
GPG key ID: 076E7C3D44720826
52 changed files with 1978 additions and 2458 deletions

View file

@ -115,12 +115,12 @@ XMLPUBFUN htmlParserCtxtPtr XMLCALL
XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL
htmlParseDocument(htmlParserCtxtPtr ctxt); htmlParseDocument(htmlParserCtxtPtr ctxt);
XMLPUBFUN htmlDocPtr XMLCALL XMLPUBFUN htmlDocPtr XMLCALL
htmlSAXParseDoc (xmlChar *cur, htmlSAXParseDoc (const xmlChar *cur,
const char *encoding, const char *encoding,
htmlSAXHandlerPtr sax, htmlSAXHandlerPtr sax,
void *userData); void *userData);
XMLPUBFUN htmlDocPtr XMLCALL XMLPUBFUN htmlDocPtr XMLCALL
htmlParseDoc (xmlChar *cur, htmlParseDoc (const xmlChar *cur,
const char *encoding); const char *encoding);
XMLPUBFUN htmlDocPtr XMLCALL XMLPUBFUN htmlDocPtr XMLCALL
htmlSAXParseFile(const char *filename, htmlSAXParseFile(const char *filename,

View file

@ -16,7 +16,7 @@
#ifdef LIBXML_FTP_ENABLED #ifdef LIBXML_FTP_ENABLED
/* Needed for portability to Windows 64 bits */ /* Needed for portability to Windows 64 bits */
#if defined(__MINGW32__) || defined(_WIN32_WCE) #if defined(_WIN32) && !defined(__CYGWIN__)
#include <winsock2.h> #include <winsock2.h>
#else #else
/** /**

View file

@ -3,7 +3,7 @@
* Description: internal interfaces for the XML Schemas handling * Description: internal interfaces for the XML Schemas handling
* and schema validity checking * and schema validity checking
* The Schemas development is a Work In Progress. * The Schemas development is a Work In Progress.
* Some of those interfaces are not garanteed to be API or ABI stable ! * Some of those interfaces are not guaranteed to be API or ABI stable !
* *
* Copy: See Copyright for the status of this software. * Copy: See Copyright for the status of this software.
* *

View file

@ -72,8 +72,13 @@ XMLPUBFUN void XMLCALL
XMLPUBFUN xmlGlobalStatePtr XMLCALL XMLPUBFUN xmlGlobalStatePtr XMLCALL
xmlGetGlobalState(void); xmlGetGlobalState(void);
#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && defined(LIBXML_STATIC_FOR_DLL) #ifdef HAVE_PTHREAD_H
int XMLCALL xmlDllMain(void *hinstDLL, unsigned long fdwReason, void *lpvReserved); #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
#if defined(LIBXML_STATIC_FOR_DLL)
int XMLCALL
xmlDllMain(void *hinstDLL, unsigned long fdwReason,
void *lpvReserved);
#endif
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -393,7 +393,7 @@ typedef void * xmlTextReaderLocatorPtr;
* @arg: the user argument * @arg: the user argument
* @msg: the message * @msg: the message
* @severity: the severity of the error * @severity: the severity of the error
* @locator: a locator indicating where the error occured * @locator: a locator indicating where the error occurred
* *
* Signature of an error callback from a reader parser * Signature of an error callback from a reader parser
*/ */

View file

@ -29,28 +29,28 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version);
* *
* the version string like "1.2.3" * the version string like "1.2.3"
*/ */
#define LIBXML_DOTTED_VERSION "2.9.4" #define LIBXML_DOTTED_VERSION "2.9.7"
/** /**
* LIBXML_VERSION: * LIBXML_VERSION:
* *
* the version number: 1.2.3 value is 10203 * the version number: 1.2.3 value is 10203
*/ */
#define LIBXML_VERSION 20904 #define LIBXML_VERSION 20907
/** /**
* LIBXML_VERSION_STRING: * LIBXML_VERSION_STRING:
* *
* the version number string, 1.2.3 value is "10203" * the version number string, 1.2.3 value is "10203"
*/ */
#define LIBXML_VERSION_STRING "20904" #define LIBXML_VERSION_STRING "20907"
/** /**
* LIBXML_VERSION_EXTRA: * LIBXML_VERSION_EXTRA:
* *
* extra version information, used to show a CVS compilation * extra version information, used to show a CVS compilation
*/ */
#define LIBXML_VERSION_EXTRA "-GITCVE-2016-1834-21-g502f6a6" #define LIBXML_VERSION_EXTRA "-GITv2.9.7-rc1"
/** /**
* LIBXML_TEST_VERSION: * LIBXML_TEST_VERSION:
@ -58,7 +58,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version);
* Macro to check that the libxml version in use is compatible with * Macro to check that the libxml version in use is compatible with
* the version the software has been compiled against * the version the software has been compiled against
*/ */
#define LIBXML_TEST_VERSION xmlCheckVersion(20904); #define LIBXML_TEST_VERSION xmlCheckVersion(20907);
#ifndef VMS #ifndef VMS
#if 0 #if 0

View file

@ -1929,7 +1929,7 @@ Mon Jun 12 12:54:25 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* tree.c: Fixed xmlGetNodePath() to generate the node test "*" * tree.c: Fixed xmlGetNodePath() to generate the node test "*"
for elements in the default namespace, rather than generating for elements in the default namespace, rather than generating
an unprefixed named node test and loosing the namespace an unprefixed named node test and losing the namespace
information. information.
Fri Jun 9 21:45:02 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net> Fri Jun 9 21:45:02 CEST 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
@ -2305,7 +2305,7 @@ Mon Mar 6 14:21:08 CET 2006 Kasimier Buchcik <libxml2-cvs@cazic.net>
* tree.c: Simplified usage of the internal xmlNsMap. Added a * tree.c: Simplified usage of the internal xmlNsMap. Added a
"strict" lookup for namespaces based on a prefix. Fixed a "strict" lookup for namespaces based on a prefix. Fixed a
namespace processing issue in the clone-node function, which namespace processing issue in the clone-node function, which
occured if a @ctxt argument was given. occurred if a @ctxt argument was given.
Fri Mar 3 17:44:10 CET 2006 Rob Richards <rrichards@ctindustries.net> Fri Mar 3 17:44:10 CET 2006 Rob Richards <rrichards@ctindustries.net>
@ -3951,7 +3951,7 @@ Thu Jun 30 15:01:52 CEST 2005 Daniel Veillard <daniel@veillard.com>
* README: updated * README: updated
* debugXML.c: fix a bug raised by bill on IRC * debugXML.c: fix a bug raised by bill on IRC
* relaxng.c: fix a leak in weird circumstances * relaxng.c: fix a leak in weird circumstances
* runsuite.c Makefile.am: standalone test tool agaisnt * runsuite.c Makefile.am: standalone test tool against
the regression suites, work in progress the regression suites, work in progress
Tue Jun 28 08:30:26 CEST 2005 Daniel Veillard <daniel@veillard.com> Tue Jun 28 08:30:26 CEST 2005 Daniel Veillard <daniel@veillard.com>
@ -4356,7 +4356,7 @@ Fri Apr 8 21:58:04 CEST 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Added substitution group constraints; changed * xmlschemas.c: Added substitution group constraints; changed
the build of the pre-computed substitution groups. Channeled the build of the pre-computed substitution groups. Channeled
errors during xsi assembling of schemas to the validation errors during xsi assembling of schemas to the validation
context. Fixed a big memory leak, which occured when using context. Fixed a big memory leak, which occurred when using
IDCs: the precomputed value of attributes was not freed if IDCs: the precomputed value of attributes was not freed if
the attribute did not resolve to an IDC field (discovered the attribute did not resolve to an IDC field (discovered
with the help of Randy J. Ray's schema, posted to the with the help of Randy J. Ray's schema, posted to the
@ -4551,7 +4551,7 @@ Mon Mar 21 22:58:37 CET 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
Mon Mar 21 21:09:07 CET 2005 Kasimier Buchcik <libxml2-cvs@cazic.net> Mon Mar 21 21:09:07 CET 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
* xmlschemas.c: Fixed a segfault, which occured during bubbling * xmlschemas.c: Fixed a segfault, which occurred during bubbling
of IDC nodes (bug #170779 and #170778, reported by GUY Fabrice): of IDC nodes (bug #170779 and #170778, reported by GUY Fabrice):
a variable was missed to be reset in a loop. Deactivated bubbling, a variable was missed to be reset in a loop. Deactivated bubbling,
if not referenced by a keyref. if not referenced by a keyref.
@ -11220,7 +11220,7 @@ Fri Mar 7 19:29:40 CET 2003 Daniel Veillard <daniel@veillard.com>
* test/xsdtest/xsdtest.xml uri.c: after and exchange with James * test/xsdtest/xsdtest.xml uri.c: after and exchange with James
Clark it appeared I had bug in URI parsing code ... Clark it appeared I had bug in URI parsing code ...
* relaxng.c include/libxml/relaxng.h: completely revamped error * relaxng.c include/libxml/relaxng.h: completely revamped error
reporting to not loose message from optional parts. reporting to not lose message from optional parts.
* xmllint.c: added timing for RNG validation steps * xmllint.c: added timing for RNG validation steps
* result/relaxng/*: updated the result, all error messages changed * result/relaxng/*: updated the result, all error messages changed
@ -13182,7 +13182,7 @@ Thu Aug 1 12:17:30 CEST 2002 Daniel Veillard <daniel@veillard.com>
xmlNewCharEncodingHandler as requested in #89415 xmlNewCharEncodingHandler as requested in #89415
* python/generator.py python/setup.py.in: applied cleanup * python/generator.py python/setup.py.in: applied cleanup
patches from Marc-Andre Lemburg patches from Marc-Andre Lemburg
* tree.c: fixing bug #89332 on a specific case of loosing * tree.c: fixing bug #89332 on a specific case of losing
the XML-1.0 namespace on xml:xxx attributes the XML-1.0 namespace on xml:xxx attributes
Wed Jul 31 23:27:42 2002 Aleksey Sanin <aleksey@aleksey.com> Wed Jul 31 23:27:42 2002 Aleksey Sanin <aleksey@aleksey.com>
@ -15356,7 +15356,7 @@ Sat Oct 6 15:27:12 CEST 2001 Daniel Veillard <daniel@veillard.com>
Sat Oct 6 15:07:14 CEST 2001 Daniel Veillard <daniel@veillard.com> Sat Oct 6 15:07:14 CEST 2001 Daniel Veillard <daniel@veillard.com>
* xpath.c: fixing #61673 part I, do not loose doc information * xpath.c: fixing #61673 part I, do not lose doc information
when copying result value trees. when copying result value trees.
Sat Oct 6 11:58:58 CEST 2001 Daniel Veillard <daniel@veillard.com> Sat Oct 6 11:58:58 CEST 2001 Daniel Veillard <daniel@veillard.com>
@ -15970,7 +15970,7 @@ Tue Jul 10 17:47:09 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
Mon Jul 9 22:06:53 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Mon Jul 9 22:06:53 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* valid.c: fixed "Internal: MIXED struct bad" when #CDATA elements * valid.c: fixed "Internal: MIXED struct bad" when #CDATA elements
validation occured on content with element child validation occurred on content with element child
Mon Jul 9 17:59:08 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Mon Jul 9 17:59:08 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>

View file

@ -2528,8 +2528,12 @@ htmlParseNameComplex(xmlParserCtxtPtr ctxt) {
} }
} }
if (ctxt->input->base > ctxt->input->cur - len) if (ctxt->input->cur - ctxt->input->base < len) {
return(NULL); /* Sanity check */
htmlParseErr(ctxt, XML_ERR_INTERNAL_ERROR,
"unexpected change of input buffer", NULL, NULL);
return (NULL);
}
return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len)); return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
} }
@ -4444,7 +4448,7 @@ static void
htmlParseElementInternal(htmlParserCtxtPtr ctxt) { htmlParseElementInternal(htmlParserCtxtPtr ctxt) {
const xmlChar *name; const xmlChar *name;
const htmlElemDesc * info; const htmlElemDesc * info;
htmlParserNodeInfo node_info = { 0, }; htmlParserNodeInfo node_info = { NULL, 0, 0, 0, 0 };
int failed; int failed;
if ((ctxt == NULL) || (ctxt->input == NULL)) { if ((ctxt == NULL) || (ctxt->input == NULL)) {
@ -4941,6 +4945,7 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt)
ctxt->wellFormed = 1; ctxt->wellFormed = 1;
ctxt->replaceEntities = 0; ctxt->replaceEntities = 0;
ctxt->linenumbers = xmlLineNumbersDefaultValue; ctxt->linenumbers = xmlLineNumbersDefaultValue;
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
ctxt->html = 1; ctxt->html = 1;
ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0; ctxt->vctxt.finishDtd = XML_CTXT_FINISH_DTD_0;
ctxt->vctxt.userData = ctxt; ctxt->vctxt.userData = ctxt;
@ -6273,7 +6278,8 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
*/ */
htmlDocPtr htmlDocPtr
htmlSAXParseDoc(xmlChar *cur, const char *encoding, htmlSAXHandlerPtr sax, void *userData) { htmlSAXParseDoc(const xmlChar *cur, const char *encoding,
htmlSAXHandlerPtr sax, void *userData) {
htmlDocPtr ret; htmlDocPtr ret;
htmlParserCtxtPtr ctxt; htmlParserCtxtPtr ctxt;
@ -6312,7 +6318,7 @@ htmlSAXParseDoc(xmlChar *cur, const char *encoding, htmlSAXHandlerPtr sax, void
*/ */
htmlDocPtr htmlDocPtr
htmlParseDoc(xmlChar *cur, const char *encoding) { htmlParseDoc(const xmlChar *cur, const char *encoding) {
return(htmlSAXParseDoc(cur, encoding, NULL, NULL)); return(htmlSAXParseDoc(cur, encoding, NULL, NULL));
} }

View file

@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <stddef.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/parser.h> #include <libxml/parser.h>
@ -1181,6 +1182,8 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement"); xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
if (name != NULL) if (name != NULL)
xmlFree(name); xmlFree(name);
if (nval != NULL)
xmlFree(nval);
return; return;
} }
} else { } else {
@ -1242,6 +1245,8 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
xmlFree(ns); xmlFree(ns);
if (name != NULL) if (name != NULL)
xmlFree(name); xmlFree(name);
if (nval != NULL)
xmlFree(nval);
return; return;
} }
} else { } else {
@ -1311,6 +1316,8 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
name, namespace->href); name, namespace->href);
ctxt->wellFormed = 0; ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1; if (ctxt->recovery == 0) ctxt->disableSAX = 1;
if (name != NULL)
xmlFree(name);
goto error; goto error;
} }
} }
@ -1908,7 +1915,7 @@ skip:
else { else {
ret->line = 65535; ret->line = 65535;
if (ctxt->options & XML_PARSE_BIG_LINES) if (ctxt->options & XML_PARSE_BIG_LINES)
ret->psvi = (void *) (long) ctxt->input->line; ret->psvi = (void *) (ptrdiff_t) ctxt->input->line;
} }
} }
} }
@ -2311,7 +2318,7 @@ xmlSAX2StartElementNs(void *ctx,
} else { } else {
/* /*
* any out of memory error would already have been raised * any out of memory error would already have been raised
* but we can't be garanteed it's the actual error due to the * but we can't be guaranteed it's the actual error due to the
* API, best is to skip in this case * API, best is to skip in this case
*/ */
continue; continue;
@ -2805,7 +2812,8 @@ xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len)
xmlTextConcat(lastChild, value, len); xmlTextConcat(lastChild, value, len);
} else { } else {
ret = xmlNewCDataBlock(ctxt->myDoc, value, len); ret = xmlNewCDataBlock(ctxt->myDoc, value, len);
xmlAddChild(ctxt->node, ret); if (xmlAddChild(ctxt->node, ret) == NULL)
xmlFreeNode(ret);
} }
} }

View file

@ -49,7 +49,7 @@ struct _xmlBuf {
size_t use; /* The buffer size used */ size_t use; /* The buffer size used */
size_t size; /* The buffer size */ size_t size; /* The buffer size */
xmlBufferPtr buffer; /* wrapper for an old buffer */ xmlBufferPtr buffer; /* wrapper for an old buffer */
int error; /* an error code if a failure occured */ int error; /* an error code if a failure occurred */
}; };
#ifdef WITH_BUFFER_COMPAT #ifdef WITH_BUFFER_COMPAT
@ -231,7 +231,7 @@ xmlBufPtr
xmlBufCreateStatic(void *mem, size_t size) { xmlBufCreateStatic(void *mem, size_t size) {
xmlBufPtr ret; xmlBufPtr ret;
if ((mem == NULL) || (size == 0)) if (mem == NULL)
return(NULL); return(NULL);
ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf)); ret = (xmlBufPtr) xmlMalloc(sizeof(xmlBuf));
@ -701,7 +701,7 @@ xmlBufUse(const xmlBufPtr buf)
* used in the buffer. It does not account for the terminating zero * used in the buffer. It does not account for the terminating zero
* usually needed * usually needed
* *
* Returns the amount or 0 if none or an error occured * Returns the amount or 0 if none or an error occurred
*/ */
size_t size_t

View file

@ -1375,13 +1375,6 @@ xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur)
xmlFreeURI(uri); xmlFreeURI(uri);
return (-1); return (-1);
} }
if ((xmlStrcasecmp((const xmlChar *) uri->scheme, BAD_CAST "urn") != 0)
&& (xmlStrcasecmp((const xmlChar *) uri->scheme, BAD_CAST "dav") !=0)
&& (xmlStrlen((const xmlChar *) uri->server) == 0)) {
xmlC14NErrRelativeNamespace(uri->scheme);
xmlFreeURI(uri);
return (-1);
}
xmlFreeURI(uri); xmlFreeURI(uri);
} }
ns = ns->next; ns = ns->next;

View file

@ -2396,6 +2396,7 @@ xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value,
case SGML_CATA_ENTITY: case SGML_CATA_ENTITY:
if (*cur == '%') if (*cur == '%')
type = SGML_CATA_PENTITY; type = SGML_CATA_PENTITY;
/* Falls through. */
case SGML_CATA_PENTITY: case SGML_CATA_PENTITY:
case SGML_CATA_DOCTYPE: case SGML_CATA_DOCTYPE:
case SGML_CATA_LINKTYPE: case SGML_CATA_LINKTYPE:

View file

@ -275,8 +275,7 @@
/* Define as const if the declaration of iconv() needs const. */ /* Define as const if the declaration of iconv() needs const. */
/* #undef ICONV_CONST */ /* #undef ICONV_CONST */
/* Define to the sub-directory in which libtool stores uninstalled libraries. /* Define to the sub-directory where libtool stores uninstalled libraries. */
*/
/* #undef LT_OBJDIR */ /* #undef LT_OBJDIR */
/* Name of package */ /* Name of package */
@ -323,9 +322,6 @@
#define below would cause a syntax error. */ #define below would cause a syntax error. */
/* #undef _UINT32_T */ /* #undef _UINT32_T */
/* Using the Win32 Socket implementation */
//#define _WINSOCKAPI_ 1
/* ss_family is not defined here, use __ss_family instead */ /* ss_family is not defined here, use __ss_family instead */
/* #undef ss_family */ /* #undef ss_family */

View file

@ -2931,7 +2931,7 @@ xmlShell(xmlDocPtr doc, char *filename, xmlShellReadlineFunc input,
fprintf(ctxt->output, "\tvalidate check the document for errors\n"); fprintf(ctxt->output, "\tvalidate check the document for errors\n");
#endif /* LIBXML_VALID_ENABLED */ #endif /* LIBXML_VALID_ENABLED */
#ifdef LIBXML_SCHEMAS_ENABLED #ifdef LIBXML_SCHEMAS_ENABLED
fprintf(ctxt->output, "\trelaxng rng validate the document agaisnt the Relax-NG schemas\n"); fprintf(ctxt->output, "\trelaxng rng validate the document against the Relax-NG schemas\n");
#endif #endif
fprintf(ctxt->output, "\tgrep string search for a string in the subtree\n"); fprintf(ctxt->output, "\tgrep string search for a string in the subtree\n");
#ifdef LIBXML_VALID_ENABLED #ifdef LIBXML_VALID_ENABLED

View file

@ -48,7 +48,7 @@
#else #else
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#elif defined(WIN32) #elif defined(_WIN32)
typedef unsigned __int32 uint32_t; typedef unsigned __int32 uint32_t;
#endif #endif
#endif #endif
@ -249,7 +249,7 @@ xmlDictAddString(xmlDictPtr dict, const xmlChar *name, unsigned int namelen) {
#endif #endif
pool = dict->strings; pool = dict->strings;
while (pool != NULL) { while (pool != NULL) {
if (pool->end - pool->free > namelen) if ((size_t)(pool->end - pool->free) > namelen)
goto found_pool; goto found_pool;
if (pool->size > size) size = pool->size; if (pool->size > size) size = pool->size;
limit += pool->size; limit += pool->size;
@ -317,7 +317,7 @@ xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix, unsigned int plen,
#endif #endif
pool = dict->strings; pool = dict->strings;
while (pool != NULL) { while (pool != NULL) {
if (pool->end - pool->free > namelen + plen + 1) if ((size_t)(pool->end - pool->free) > namelen + plen + 1)
goto found_pool; goto found_pool;
if (pool->size > size) size = pool->size; if (pool->size > size) size = pool->size;
limit += pool->size; limit += pool->size;
@ -453,14 +453,23 @@ xmlDictComputeFastKey(const xmlChar *name, int namelen, int seed) {
} }
switch (namelen) { switch (namelen) {
case 10: value += name[9]; case 10: value += name[9];
/* Falls through. */
case 9: value += name[8]; case 9: value += name[8];
/* Falls through. */
case 8: value += name[7]; case 8: value += name[7];
/* Falls through. */
case 7: value += name[6]; case 7: value += name[6];
/* Falls through. */
case 6: value += name[5]; case 6: value += name[5];
/* Falls through. */
case 5: value += name[4]; case 5: value += name[4];
/* Falls through. */
case 4: value += name[3]; case 4: value += name[3];
/* Falls through. */
case 3: value += name[2]; case 3: value += name[2];
/* Falls through. */
case 2: value += name[1]; case 2: value += name[1];
/* Falls through. */
default: break; default: break;
} }
return(value); return(value);
@ -496,15 +505,25 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
} }
switch (plen) { switch (plen) {
case 10: value += prefix[9]; case 10: value += prefix[9];
/* Falls through. */
case 9: value += prefix[8]; case 9: value += prefix[8];
/* Falls through. */
case 8: value += prefix[7]; case 8: value += prefix[7];
/* Falls through. */
case 7: value += prefix[6]; case 7: value += prefix[6];
/* Falls through. */
case 6: value += prefix[5]; case 6: value += prefix[5];
/* Falls through. */
case 5: value += prefix[4]; case 5: value += prefix[4];
/* Falls through. */
case 4: value += prefix[3]; case 4: value += prefix[3];
/* Falls through. */
case 3: value += prefix[2]; case 3: value += prefix[2];
/* Falls through. */
case 2: value += prefix[1]; case 2: value += prefix[1];
/* Falls through. */
case 1: value += prefix[0]; case 1: value += prefix[0];
/* Falls through. */
default: break; default: break;
} }
len -= plen; len -= plen;
@ -514,15 +533,25 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
} }
switch (len) { switch (len) {
case 10: value += name[9]; case 10: value += name[9];
/* Falls through. */
case 9: value += name[8]; case 9: value += name[8];
/* Falls through. */
case 8: value += name[7]; case 8: value += name[7];
/* Falls through. */
case 7: value += name[6]; case 7: value += name[6];
/* Falls through. */
case 6: value += name[5]; case 6: value += name[5];
/* Falls through. */
case 5: value += name[4]; case 5: value += name[4];
/* Falls through. */
case 4: value += name[3]; case 4: value += name[3];
/* Falls through. */
case 3: value += name[2]; case 3: value += name[2];
/* Falls through. */
case 2: value += name[1]; case 2: value += name[1];
/* Falls through. */
case 1: value += name[0]; case 1: value += name[0];
/* Falls through. */
default: break; default: break;
} }
return(value); return(value);
@ -533,7 +562,7 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
* *
* Create a new dictionary * Create a new dictionary
* *
* Returns the newly created dictionary, or NULL if an error occured. * Returns the newly created dictionary, or NULL if an error occurred.
*/ */
xmlDictPtr xmlDictPtr
xmlDictCreate(void) { xmlDictCreate(void) {
@ -580,7 +609,7 @@ xmlDictCreate(void) {
* new dictionary, then in @sub, and if not found are created in the * new dictionary, then in @sub, and if not found are created in the
* new dictionary. * new dictionary.
* *
* Returns the newly created dictionary, or NULL if an error occured. * Returns the newly created dictionary, or NULL if an error occurred.
*/ */
xmlDictPtr xmlDictPtr
xmlDictCreateSub(xmlDictPtr sub) { xmlDictCreateSub(xmlDictPtr sub) {
@ -699,7 +728,7 @@ xmlDictGrow(xmlDictPtr dict, size_t size) {
} else { } else {
/* /*
* we don't have much ways to alert from herei * we don't have much ways to alert from herei
* result is loosing an entry and unicity garantee * result is losing an entry and unicity guarantee
*/ */
ret = -1; ret = -1;
} }

View file

@ -11,7 +11,7 @@
#ifdef IN_LIBXML #ifdef IN_LIBXML
#ifdef __GNUC__ #ifdef __GNUC__
#ifdef PIC #ifdef PIC
#ifdef linux #ifdef __linux__
#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3) #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3)
#include "libxml/c14n.h" #include "libxml/c14n.h"

View file

@ -354,8 +354,14 @@ UTF8ToUTF8(unsigned char* out, int *outlen,
{ {
int len; int len;
if ((out == NULL) || (inb == NULL) || (outlen == NULL) || (inlenb == NULL)) if ((out == NULL) || (outlen == NULL) || (inlenb == NULL))
return(-1); return(-1);
if (inb == NULL) {
/* inb == NULL means output is initialized. */
*outlen = 0;
*inlenb = 0;
return(0);
}
if (*outlen > *inlenb) { if (*outlen > *inlenb) {
len = *inlenb; len = *inlenb;
} else { } else {
@ -1904,6 +1910,61 @@ xmlUconvWrapper(uconv_t *cd, int toUnicode, unsigned char *out, int *outlen,
* * * *
************************************************************************/ ************************************************************************/
static int
xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out,
int *outlen, const unsigned char *in, int *inlen) {
int ret;
if (handler->input != NULL) {
ret = handler->input(out, outlen, in, inlen);
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_in != NULL) {
ret = xmlIconvWrapper(handler->iconv_in, out, outlen, in, inlen);
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (handler->uconv_in != NULL) {
ret = xmlUconvWrapper(handler->uconv_in, 1, out, outlen, in, inlen);
}
#endif /* LIBXML_ICU_ENABLED */
else {
*outlen = 0;
*inlen = 0;
ret = -2;
}
return(ret);
}
/* Returns -4 if no output function was found. */
static int
xmlEncOutputChunk(xmlCharEncodingHandler *handler, unsigned char *out,
int *outlen, const unsigned char *in, int *inlen) {
int ret;
if (handler->output != NULL) {
ret = handler->output(out, outlen, in, inlen);
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_out != NULL) {
ret = xmlIconvWrapper(handler->iconv_out, out, outlen, in, inlen);
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (handler->uconv_out != NULL) {
ret = xmlUconvWrapper(handler->uconv_out, 0, out, outlen, in, inlen);
}
#endif /* LIBXML_ICU_ENABLED */
else {
*outlen = 0;
*inlen = 0;
ret = -4;
}
return(ret);
}
/** /**
* xmlCharEncFirstLineInt: * xmlCharEncFirstLineInt:
* @handler: char enconding transformation data structure * @handler: char enconding transformation data structure
@ -1922,7 +1983,7 @@ xmlUconvWrapper(uconv_t *cd, int toUnicode, unsigned char *out, int *outlen,
int int
xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out,
xmlBufferPtr in, int len) { xmlBufferPtr in, int len) {
int ret = -2; int ret;
int written; int written;
int toconv; int toconv;
@ -1953,33 +2014,13 @@ xmlCharEncFirstLineInt(xmlCharEncodingHandler *handler, xmlBufferPtr out,
written = out->size - out->use - 1; written = out->size - out->use - 1;
} }
if (handler->input != NULL) { ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
ret = handler->input(&out->content[out->use], &written, in->content, &toconv);
in->content, &toconv); xmlBufferShrink(in, toconv);
xmlBufferShrink(in, toconv); out->use += written;
out->use += written; out->content[out->use] = 0;
out->content[out->use] = 0; if (ret == -1) ret = -3;
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_in != NULL) {
ret = xmlIconvWrapper(handler->iconv_in, &out->content[out->use],
&written, in->content, &toconv);
xmlBufferShrink(in, toconv);
out->use += written;
out->content[out->use] = 0;
if (ret == -1) ret = -3;
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (handler->uconv_in != NULL) {
ret = xmlUconvWrapper(handler->uconv_in, 1, &out->content[out->use],
&written, in->content, &toconv);
xmlBufferShrink(in, toconv);
out->use += written;
out->content[out->use] = 0;
if (ret == -1) ret = -3;
}
#endif /* LIBXML_ICU_ENABLED */
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
switch (ret) { switch (ret) {
case 0: case 0:
@ -2049,7 +2090,7 @@ xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out,
int int
xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len) xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
{ {
int ret = -2; int ret;
size_t written; size_t written;
size_t toconv; size_t toconv;
int c_in; int c_in;
@ -2091,32 +2132,13 @@ xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
c_in = toconv; c_in = toconv;
c_out = written; c_out = written;
if (input->encoder->input != NULL) { ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
ret = input->encoder->input(xmlBufEnd(out), &c_out, xmlBufContent(in), &c_in);
xmlBufContent(in), &c_in); xmlBufShrink(in, c_in);
xmlBufShrink(in, c_in); xmlBufAddLen(out, c_out);
xmlBufAddLen(out, c_out); if (ret == -1)
} ret = -3;
#ifdef LIBXML_ICONV_ENABLED
else if (input->encoder->iconv_in != NULL) {
ret = xmlIconvWrapper(input->encoder->iconv_in, xmlBufEnd(out),
&c_out, xmlBufContent(in), &c_in);
xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
if (ret == -1)
ret = -3;
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (input->encoder->uconv_in != NULL) {
ret = xmlUconvWrapper(input->encoder->uconv_in, 1, xmlBufEnd(out),
&c_out, xmlBufContent(in), &c_in);
xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
if (ret == -1)
ret = -3;
}
#endif /* LIBXML_ICU_ENABLED */
switch (ret) { switch (ret) {
case 0: case 0:
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
@ -2175,7 +2197,7 @@ xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
int int
xmlCharEncInput(xmlParserInputBufferPtr input, int flush) xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
{ {
int ret = -2; int ret;
size_t written; size_t written;
size_t toconv; size_t toconv;
int c_in; int c_in;
@ -2208,32 +2230,13 @@ xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
c_in = toconv; c_in = toconv;
c_out = written; c_out = written;
if (input->encoder->input != NULL) { ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
ret = input->encoder->input(xmlBufEnd(out), &c_out, xmlBufContent(in), &c_in);
xmlBufContent(in), &c_in); xmlBufShrink(in, c_in);
xmlBufShrink(in, c_in); xmlBufAddLen(out, c_out);
xmlBufAddLen(out, c_out); if (ret == -1)
} ret = -3;
#ifdef LIBXML_ICONV_ENABLED
else if (input->encoder->iconv_in != NULL) {
ret = xmlIconvWrapper(input->encoder->iconv_in, xmlBufEnd(out),
&c_out, xmlBufContent(in), &c_in);
xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
if (ret == -1)
ret = -3;
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (input->encoder->uconv_in != NULL) {
ret = xmlUconvWrapper(input->encoder->uconv_in, 1, xmlBufEnd(out),
&c_out, xmlBufContent(in), &c_in);
xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
if (ret == -1)
ret = -3;
}
#endif /* LIBXML_ICU_ENABLED */
switch (ret) { switch (ret) {
case 0: case 0:
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
@ -2294,7 +2297,7 @@ int
xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out, xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out,
xmlBufferPtr in) xmlBufferPtr in)
{ {
int ret = -2; int ret;
int written; int written;
int toconv; int toconv;
@ -2313,35 +2316,14 @@ xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out,
xmlBufferGrow(out, out->size + toconv * 2); xmlBufferGrow(out, out->size + toconv * 2);
written = out->size - out->use - 1; written = out->size - out->use - 1;
} }
if (handler->input != NULL) { ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
ret = handler->input(&out->content[out->use], &written, in->content, &toconv);
in->content, &toconv); xmlBufferShrink(in, toconv);
xmlBufferShrink(in, toconv); out->use += written;
out->use += written; out->content[out->use] = 0;
out->content[out->use] = 0; if (ret == -1)
} ret = -3;
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_in != NULL) {
ret = xmlIconvWrapper(handler->iconv_in, &out->content[out->use],
&written, in->content, &toconv);
xmlBufferShrink(in, toconv);
out->use += written;
out->content[out->use] = 0;
if (ret == -1)
ret = -3;
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (handler->uconv_in != NULL) {
ret = xmlUconvWrapper(handler->uconv_in, 1, &out->content[out->use],
&written, in->content, &toconv);
xmlBufferShrink(in, toconv);
out->use += written;
out->content[out->use] = 0;
if (ret == -1)
ret = -3;
}
#endif /* LIBXML_ICU_ENABLED */
switch (ret) { switch (ret) {
case 0: case 0:
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
@ -2405,7 +2387,7 @@ xmlCharEncInFunc(xmlCharEncodingHandler * handler, xmlBufferPtr out,
int int
xmlCharEncOutput(xmlOutputBufferPtr output, int init) xmlCharEncOutput(xmlOutputBufferPtr output, int init)
{ {
int ret = -2; int ret;
size_t written; size_t written;
size_t writtentot = 0; size_t writtentot = 0;
size_t toconv; size_t toconv;
@ -2413,7 +2395,6 @@ xmlCharEncOutput(xmlOutputBufferPtr output, int init)
int c_out; int c_out;
xmlBufPtr in; xmlBufPtr in;
xmlBufPtr out; xmlBufPtr out;
int charref_len = 0;
if ((output == NULL) || (output->encoder == NULL) || if ((output == NULL) || (output->encoder == NULL) ||
(output->buffer == NULL) || (output->conv == NULL)) (output->buffer == NULL) || (output->conv == NULL))
@ -2433,26 +2414,10 @@ retry:
if (init) { if (init) {
c_in = 0; c_in = 0;
c_out = written; c_out = written;
if (output->encoder->output != NULL) { /* TODO: Check return value. */
ret = output->encoder->output(xmlBufEnd(out), &c_out, xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
NULL, &c_in); NULL, &c_in);
if (ret > 0) /* Gennady: check return value */ xmlBufAddLen(out, c_out);
xmlBufAddLen(out, c_out);
}
#ifdef LIBXML_ICONV_ENABLED
else if (output->encoder->iconv_out != NULL) {
ret = xmlIconvWrapper(output->encoder->iconv_out, xmlBufEnd(out),
&c_out, NULL, &c_in);
xmlBufAddLen(out, c_out);
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (output->encoder->uconv_out != NULL) {
ret = xmlUconvWrapper(output->encoder->uconv_out, 0, xmlBufEnd(out),
&c_out, NULL, &c_in);
xmlBufAddLen(out, c_out);
}
#endif /* LIBXML_ICU_ENABLED */
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"initialized encoder\n"); "initialized encoder\n");
@ -2477,57 +2442,17 @@ retry:
c_in = toconv; c_in = toconv;
c_out = written; c_out = written;
if (output->encoder->output != NULL) { ret = xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
ret = output->encoder->output(xmlBufEnd(out), &c_out, xmlBufContent(in), &c_in);
xmlBufContent(in), &c_in); xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
writtentot += c_out;
if (ret == -1) {
if (c_out > 0) { if (c_out > 0) {
xmlBufShrink(in, c_in); /* Can be a limitation of iconv or uconv */
xmlBufAddLen(out, c_out); goto retry;
writtentot += c_out;
} }
} ret = -3;
#ifdef LIBXML_ICONV_ENABLED
else if (output->encoder->iconv_out != NULL) {
ret = xmlIconvWrapper(output->encoder->iconv_out, xmlBufEnd(out),
&c_out, xmlBufContent(in), &c_in);
xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
writtentot += c_out;
if (ret == -1) {
if (c_out > 0) {
/*
* Can be a limitation of iconv
*/
charref_len = 0;
goto retry;
}
ret = -3;
}
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (output->encoder->uconv_out != NULL) {
ret = xmlUconvWrapper(output->encoder->uconv_out, 0, xmlBufEnd(out),
&c_out, xmlBufContent(in), &c_in);
xmlBufShrink(in, c_in);
xmlBufAddLen(out, c_out);
writtentot += c_out;
if (ret == -1) {
if (c_out > 0) {
/*
* Can be a limitation of uconv
*/
charref_len = 0;
goto retry;
}
ret = -3;
}
}
#endif /* LIBXML_ICU_ENABLED */
else {
xmlEncodingErr(XML_I18N_NO_OUTPUT,
"xmlCharEncOutFunc: no output function !\n", NULL);
return(-1);
} }
if (ret >= 0) output += ret; if (ret >= 0) output += ret;
@ -2555,47 +2480,44 @@ retry:
c_in, c_out, (int) xmlBufUse(in)); c_in, c_out, (int) xmlBufUse(in));
#endif #endif
break; break;
case -4:
xmlEncodingErr(XML_I18N_NO_OUTPUT,
"xmlCharEncOutFunc: no output function !\n", NULL);
ret = -1;
break;
case -2: { case -2: {
xmlChar charref[20];
int len = (int) xmlBufUse(in); int len = (int) xmlBufUse(in);
xmlChar *content = xmlBufContent(in); xmlChar *content = xmlBufContent(in);
int cur; int cur, charrefLen;
cur = xmlGetUTF8Char(content, &len); cur = xmlGetUTF8Char(content, &len);
if ((charref_len != 0) && (c_out < charref_len)) { if (cur <= 0)
/*
* We attempted to insert a character reference and failed.
* Undo what was written and skip the remaining charref.
*/
xmlBufErase(out, c_out);
writtentot -= c_out;
xmlBufShrink(in, charref_len - c_out);
charref_len = 0;
ret = -1;
break; break;
} else if (cur > 0) {
xmlChar charref[20];
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"handling output conversion error\n"); "handling output conversion error\n");
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
content[0], content[1], content[0], content[1],
content[2], content[3]); content[2], content[3]);
#endif #endif
/* /*
* Removes the UTF8 sequence, and replace it by a charref * Removes the UTF8 sequence, and replace it by a charref
* and continue the transcoding phase, hoping the error * and continue the transcoding phase, hoping the error
* did not mangle the encoder state. * did not mangle the encoder state.
*/ */
charref_len = snprintf((char *) &charref[0], sizeof(charref), charrefLen = snprintf((char *) &charref[0], sizeof(charref),
"&#%d;", cur); "&#%d;", cur);
xmlBufShrink(in, len); xmlBufShrink(in, len);
xmlBufAddHead(in, charref, -1); xmlBufGrow(out, charrefLen * 4);
c_out = xmlBufAvail(out) - 1;
c_in = charrefLen;
ret = xmlEncOutputChunk(output->encoder, xmlBufEnd(out), &c_out,
charref, &c_in);
goto retry; if ((ret < 0) || (c_in != charrefLen)) {
} else {
char buf[50]; char buf[50];
snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X", snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
@ -2607,8 +2529,12 @@ retry:
buf); buf);
if (xmlBufGetAllocationScheme(in) != XML_BUFFER_ALLOC_IMMUTABLE) if (xmlBufGetAllocationScheme(in) != XML_BUFFER_ALLOC_IMMUTABLE)
content[0] = ' '; content[0] = ' ';
break;
} }
break;
xmlBufAddLen(out, c_out);
writtentot += c_out;
goto retry;
} }
} }
return(ret); return(ret);
@ -2636,12 +2562,11 @@ retry:
int int
xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlCharEncOutFunc(xmlCharEncodingHandler *handler, xmlBufferPtr out,
xmlBufferPtr in) { xmlBufferPtr in) {
int ret = -2; int ret;
int written; int written;
int writtentot = 0; int writtentot = 0;
int toconv; int toconv;
int output = 0; int output = 0;
int charref_len = 0;
if (handler == NULL) return(-1); if (handler == NULL) return(-1);
if (out == NULL) return(-1); if (out == NULL) return(-1);
@ -2658,31 +2583,11 @@ retry:
*/ */
if (in == NULL) { if (in == NULL) {
toconv = 0; toconv = 0;
if (handler->output != NULL) { /* TODO: Check return value. */
ret = handler->output(&out->content[out->use], &written, xmlEncOutputChunk(handler, &out->content[out->use], &written,
NULL, &toconv); NULL, &toconv);
if (ret >= 0) { /* Gennady: check return value */ out->use += written;
out->use += written; out->content[out->use] = 0;
out->content[out->use] = 0;
}
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_out != NULL) {
ret = xmlIconvWrapper(handler->iconv_out, &out->content[out->use],
&written, NULL, &toconv);
out->use += written;
out->content[out->use] = 0;
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (handler->uconv_out != NULL) {
ret = xmlUconvWrapper(handler->uconv_out, 0,
&out->content[out->use],
&written, NULL, &toconv);
out->use += written;
out->content[out->use] = 0;
}
#endif /* LIBXML_ICU_ENABLED */
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"initialized encoder\n"); "initialized encoder\n");
@ -2700,61 +2605,18 @@ retry:
xmlBufferGrow(out, toconv * 4); xmlBufferGrow(out, toconv * 4);
written = out->size - out->use - 1; written = out->size - out->use - 1;
} }
if (handler->output != NULL) { ret = xmlEncOutputChunk(handler, &out->content[out->use], &written,
ret = handler->output(&out->content[out->use], &written, in->content, &toconv);
in->content, &toconv); xmlBufferShrink(in, toconv);
if (written > 0) { out->use += written;
xmlBufferShrink(in, toconv); writtentot += written;
out->use += written; out->content[out->use] = 0;
writtentot += written; if (ret == -1) {
} if (written > 0) {
out->content[out->use] = 0; /* Can be a limitation of iconv or uconv */
} goto retry;
#ifdef LIBXML_ICONV_ENABLED }
else if (handler->iconv_out != NULL) { ret = -3;
ret = xmlIconvWrapper(handler->iconv_out, &out->content[out->use],
&written, in->content, &toconv);
xmlBufferShrink(in, toconv);
out->use += written;
writtentot += written;
out->content[out->use] = 0;
if (ret == -1) {
if (written > 0) {
/*
* Can be a limitation of iconv
*/
charref_len = 0;
goto retry;
}
ret = -3;
}
}
#endif /* LIBXML_ICONV_ENABLED */
#ifdef LIBXML_ICU_ENABLED
else if (handler->uconv_out != NULL) {
ret = xmlUconvWrapper(handler->uconv_out, 0,
&out->content[out->use],
&written, in->content, &toconv);
xmlBufferShrink(in, toconv);
out->use += written;
writtentot += written;
out->content[out->use] = 0;
if (ret == -1) {
if (written > 0) {
/*
* Can be a limitation of iconv
*/
charref_len = 0;
goto retry;
}
ret = -3;
}
}
#endif /* LIBXML_ICU_ENABLED */
else {
xmlEncodingErr(XML_I18N_NO_OUTPUT,
"xmlCharEncOutFunc: no output function !\n", NULL);
return(-1);
} }
if (ret >= 0) output += ret; if (ret >= 0) output += ret;
@ -2782,47 +2644,44 @@ retry:
toconv, written, in->use); toconv, written, in->use);
#endif #endif
break; break;
case -4:
xmlEncodingErr(XML_I18N_NO_OUTPUT,
"xmlCharEncOutFunc: no output function !\n", NULL);
ret = -1;
break;
case -2: { case -2: {
xmlChar charref[20];
int len = in->use; int len = in->use;
const xmlChar *utf = (const xmlChar *) in->content; const xmlChar *utf = (const xmlChar *) in->content;
int cur; int cur, charrefLen;
cur = xmlGetUTF8Char(utf, &len); cur = xmlGetUTF8Char(utf, &len);
if ((charref_len != 0) && (written < charref_len)) { if (cur <= 0)
/*
* We attempted to insert a character reference and failed.
* Undo what was written and skip the remaining charref.
*/
out->use -= written;
writtentot -= written;
xmlBufferShrink(in, charref_len - written);
charref_len = 0;
ret = -1;
break; break;
} else if (cur > 0) {
xmlChar charref[20];
#ifdef DEBUG_ENCODING #ifdef DEBUG_ENCODING
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"handling output conversion error\n"); "handling output conversion error\n");
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n", "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
in->content[0], in->content[1], in->content[0], in->content[1],
in->content[2], in->content[3]); in->content[2], in->content[3]);
#endif #endif
/* /*
* Removes the UTF8 sequence, and replace it by a charref * Removes the UTF8 sequence, and replace it by a charref
* and continue the transcoding phase, hoping the error * and continue the transcoding phase, hoping the error
* did not mangle the encoder state. * did not mangle the encoder state.
*/ */
charref_len = snprintf((char *) &charref[0], sizeof(charref), charrefLen = snprintf((char *) &charref[0], sizeof(charref),
"&#%d;", cur); "&#%d;", cur);
xmlBufferShrink(in, len); xmlBufferShrink(in, len);
xmlBufferAddHead(in, charref, -1); xmlBufferGrow(out, charrefLen * 4);
written = out->size - out->use - 1;
toconv = charrefLen;
ret = xmlEncOutputChunk(handler, &out->content[out->use], &written,
charref, &toconv);
goto retry; if ((ret < 0) || (toconv != charrefLen)) {
} else {
char buf[50]; char buf[50];
snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X", snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
@ -2834,8 +2693,13 @@ retry:
buf); buf);
if (in->alloc != XML_BUFFER_ALLOC_IMMUTABLE) if (in->alloc != XML_BUFFER_ALLOC_IMMUTABLE)
in->content[0] = ' '; in->content[0] = ' ';
break;
} }
break;
out->use += written;
writtentot += written;
out->content[out->use] = 0;
goto retry;
} }
} }
return(ret); return(ret);
@ -2954,54 +2818,20 @@ xmlByteConsumed(xmlParserCtxtPtr ctxt) {
int ret; int ret;
if (handler->output != NULL) { do {
do { toconv = in->end - cur;
toconv = in->end - cur; written = 32000;
written = 32000; ret = xmlEncOutputChunk(handler, &convbuf[0], &written,
ret = handler->output(&convbuf[0], &written, cur, &toconv);
cur, &toconv); if (ret < 0) {
if (ret == -1) return(-1); if (written > 0)
unused += written; ret = -2;
cur += toconv; else
} while (ret == -2); return(-1);
#ifdef LIBXML_ICONV_ENABLED }
} else if (handler->iconv_out != NULL) { unused += written;
do { cur += toconv;
toconv = in->end - cur; } while (ret == -2);
written = 32000;
ret = xmlIconvWrapper(handler->iconv_out, &convbuf[0],
&written, cur, &toconv);
if (ret < 0) {
if (written > 0)
ret = -2;
else
return(-1);
}
unused += written;
cur += toconv;
} while (ret == -2);
#endif
#ifdef LIBXML_ICU_ENABLED
} else if (handler->uconv_out != NULL) {
do {
toconv = in->end - cur;
written = 32000;
ret = xmlUconvWrapper(handler->uconv_out, 0, &convbuf[0],
&written, cur, &toconv);
if (ret < 0) {
if (written > 0)
ret = -2;
else
return(-1);
}
unused += written;
cur += toconv;
} while (ret == -2);
#endif
} else {
/* could not find a converter */
return(-1);
}
} }
if (in->buf->rawconsumed < unused) if (in->buf->rawconsumed < unused)
return(-1); return(-1);

View file

@ -6,6 +6,11 @@
* daniel@veillard.com * daniel@veillard.com
*/ */
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
@ -649,7 +654,7 @@ xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
} else if (*cur >= 0x80) { } else if (*cur >= 0x80) {
if (((doc != NULL) && (doc->encoding != NULL)) || (html)) { if (((doc != NULL) && (doc->encoding != NULL)) || (html)) {
/* /*
* Bjørn Reese <br@sseusa.com> provided the patch * Bjørn Reese <br@sseusa.com> provided the patch
xmlChar xc; xmlChar xc;
xc = (*cur & 0x3F) << 6; xc = (*cur & 0x3F) << 6;
if (cur[1] != 0) { if (cur[1] != 0) {

View file

@ -853,7 +853,7 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
* Get the last global error registered. This is per thread if compiled * Get the last global error registered. This is per thread if compiled
* with thread support. * with thread support.
* *
* Returns NULL if no error occured or a pointer to the error * Returns NULL if no error occurred or a pointer to the error
*/ */
xmlErrorPtr xmlErrorPtr
xmlGetLastError(void) xmlGetLastError(void)
@ -910,7 +910,7 @@ xmlResetLastError(void)
* *
* Get the last parsing error registered. * Get the last parsing error registered.
* *
* Returns NULL if no error occured or a pointer to the error * Returns NULL if no error occurred or a pointer to the error
*/ */
xmlErrorPtr xmlErrorPtr
xmlCtxtGetLastError(void *ctx) xmlCtxtGetLastError(void *ctx)

View file

@ -168,7 +168,7 @@ xmlHashComputeQKey(xmlHashTablePtr table,
* *
* Create a new xmlHashTablePtr. * Create a new xmlHashTablePtr.
* *
* Returns the newly created object, or NULL if an error occured. * Returns the newly created object, or NULL if an error occurred.
*/ */
xmlHashTablePtr xmlHashTablePtr
xmlHashCreate(int size) { xmlHashCreate(int size) {
@ -202,7 +202,7 @@ xmlHashCreate(int size) {
* *
* Create a new xmlHashTablePtr which will use @dict as the internal dictionary * Create a new xmlHashTablePtr which will use @dict as the internal dictionary
* *
* Returns the newly created object, or NULL if an error occured. * Returns the newly created object, or NULL if an error occurred.
*/ */
xmlHashTablePtr xmlHashTablePtr
xmlHashCreateDict(int size, xmlDictPtr dict) { xmlHashCreateDict(int size, xmlDictPtr dict) {

View file

@ -10,7 +10,6 @@
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
#undef HAVE_ERRNO_H #undef HAVE_ERRNO_H
#include <windows.h>
#include "wincecompat.h" #include "wincecompat.h"
#else #else
#define HAVE_SYS_STAT_H #define HAVE_SYS_STAT_H
@ -29,10 +28,6 @@
#define ICONV_CONST const #define ICONV_CONST const
#endif #endif
#ifdef NEED_SOCKETS
#include <wsockcompat.h>
#endif
/* /*
* Windows platforms may define except * Windows platforms may define except
*/ */

View file

@ -8,7 +8,7 @@
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
#include <winsock.h> #include <winsock.h>
#else #else
#undef HAVE_ERRNO_H #include <errno.h>
#include <winsock2.h> #include <winsock2.h>
/* the following is a workaround a problem for 'inline' keyword in said /* the following is a workaround a problem for 'inline' keyword in said
@ -27,60 +27,23 @@
#endif #endif
#endif #endif
#if defined( __MINGW32__ ) || defined( _MSC_VER ) #undef XML_SOCKLEN_T
/* Include <errno.h> here to ensure that it doesn't get included later #define XML_SOCKLEN_T int
* (e.g. by iconv.h) and overwrites the definition of EWOULDBLOCK. */
#include <errno.h> #ifndef ECONNRESET
#undef EWOULDBLOCK #define ECONNRESET WSAECONNRESET
#endif #endif
#ifndef EINPROGRESS
#if !defined SOCKLEN_T #define EINPROGRESS WSAEINPROGRESS
#define SOCKLEN_T int #endif
#ifndef EINTR
#define EINTR WSAEINTR
#endif
#ifndef ESHUTDOWN
#define ESHUTDOWN WSAESHUTDOWN
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif #endif
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ESHUTDOWN WSAESHUTDOWN
#if (!defined(_MSC_VER) || (_MSC_VER < 1600)) || defined(__REACTOS__)
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
#define ENOTSOCK WSAENOTSOCK
#define EDESTADDRREQ WSAEDESTADDRREQ
#define EMSGSIZE WSAEMSGSIZE
#define EPROTOTYPE WSAEPROTOTYPE
#define ENOPROTOOPT WSAENOPROTOOPT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#define EOPNOTSUPP WSAEOPNOTSUPP
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define EADDRINUSE WSAEADDRINUSE
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define ENETDOWN WSAENETDOWN
#define ENETUNREACH WSAENETUNREACH
#define ENETRESET WSAENETRESET
#define ECONNABORTED WSAECONNABORTED
#define ECONNRESET WSAECONNRESET
#define ENOBUFS WSAENOBUFS
#define EISCONN WSAEISCONN
#define ENOTCONN WSAENOTCONN
#define ETOOMANYREFS WSAETOOMANYREFS
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ELOOP WSAELOOP
#define EHOSTDOWN WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH
#define EPROCLIM WSAEPROCLIM
#define EUSERS WSAEUSERS
#define EDQUOT WSAEDQUOT
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
/* These cause conflicts with the codes from errno.h. Since they are
not used in the relevant code (nanoftp, nanohttp), we can leave
them disabled.
#define ENAMETOOLONG WSAENAMETOOLONG
#define ENOTEMPTY WSAENOTEMPTY
*/
#endif /* _MSC_VER */
#endif /* __XML_WSOCKCOMPAT_H__ */ #endif /* __XML_WSOCKCOMPAT_H__ */

View file

@ -101,7 +101,7 @@ int xmlNop(void);
#ifdef IN_LIBXML #ifdef IN_LIBXML
#ifdef __GNUC__ #ifdef __GNUC__
#ifdef PIC #ifdef PIC
#ifdef linux #ifdef __linux__
#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3) #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3)
#include "elfgcchack.h" #include "elfgcchack.h"
#endif #endif

View file

@ -347,7 +347,7 @@ void xmlListDelete(xmlListPtr l)
* *
* Remove the first instance associated to data in the list * Remove the first instance associated to data in the list
* *
* Returns 1 if a deallocation occured, or 0 if not found * Returns 1 if a deallocation occurred, or 0 if not found
*/ */
int int
xmlListRemoveFirst(xmlListPtr l, void *data) xmlListRemoveFirst(xmlListPtr l, void *data)
@ -372,7 +372,7 @@ xmlListRemoveFirst(xmlListPtr l, void *data)
* *
* Remove the last instance associated to data in the list * Remove the last instance associated to data in the list
* *
* Returns 1 if a deallocation occured, or 0 if not found * Returns 1 if a deallocation occurred, or 0 if not found
*/ */
int int
xmlListRemoveLast(xmlListPtr l, void *data) xmlListRemoveLast(xmlListPtr l, void *data)

View file

@ -12,8 +12,6 @@
#define HAVE_NETINET_IN_H #define HAVE_NETINET_IN_H
#define HAVE_NETDB_H #define HAVE_NETDB_H
#define HAVE_SYS_TIME_H #define HAVE_SYS_TIME_H
#else /* TESTING */
#define NEED_SOCKETS
#endif /* TESTING */ #endif /* TESTING */
#define IN_LIBXML #define IN_LIBXML
@ -77,14 +75,8 @@
#endif #endif
#if defined(__MINGW32__) || defined(_WIN32_WCE) #if defined(_WIN32) && !defined(__CYGWIN__)
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#endif
#include <wsockcompat.h> #include <wsockcompat.h>
#include <winsock2.h>
#undef XML_SOCKLEN_T
#define XML_SOCKLEN_T unsigned int
#endif #endif
/** /**
@ -511,6 +503,8 @@ xmlNanoFTPFreeCtxt(void * ctx) {
if (ctxt->hostname != NULL) xmlFree(ctxt->hostname); if (ctxt->hostname != NULL) xmlFree(ctxt->hostname);
if (ctxt->protocol != NULL) xmlFree(ctxt->protocol); if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
if (ctxt->path != NULL) xmlFree(ctxt->path); if (ctxt->path != NULL) xmlFree(ctxt->path);
if (ctxt->user != NULL) xmlFree(ctxt->user);
if (ctxt->passwd != NULL) xmlFree(ctxt->passwd);
ctxt->passive = 1; ctxt->passive = 1;
if (ctxt->controlFd != INVALID_SOCKET) closesocket(ctxt->controlFd); if (ctxt->controlFd != INVALID_SOCKET) closesocket(ctxt->controlFd);
ctxt->controlFd = INVALID_SOCKET; ctxt->controlFd = INVALID_SOCKET;
@ -907,7 +901,7 @@ xmlNanoFTPConnect(void *ctx) {
__xmlIOErr(XML_FROM_FTP, 0, "getaddrinfo failed"); __xmlIOErr(XML_FROM_FTP, 0, "getaddrinfo failed");
return (-1); return (-1);
} }
if (tmp->ai_addrlen > sizeof(ctxt->ftpAddr)) { if ((size_t)tmp->ai_addrlen > sizeof(ctxt->ftpAddr)) {
if (result) if (result)
freeaddrinfo (result); freeaddrinfo (result);
__xmlIOErr(XML_FROM_FTP, 0, "gethostbyname address mismatch"); __xmlIOErr(XML_FROM_FTP, 0, "gethostbyname address mismatch");
@ -1042,6 +1036,7 @@ xmlNanoFTPConnect(void *ctx) {
case 2: case 2:
if (proxyPasswd == NULL) if (proxyPasswd == NULL)
break; break;
/* Falls through. */
case 3: case 3:
if (proxyPasswd != NULL) if (proxyPasswd != NULL)
snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd); snprintf(buf, sizeof(buf), "PASS %s\r\n", proxyPasswd);
@ -1111,6 +1106,7 @@ xmlNanoFTPConnect(void *ctx) {
ctxt->controlFd = INVALID_SOCKET; ctxt->controlFd = INVALID_SOCKET;
return(-1); return(-1);
} }
/* Falls through. */
case 2: case 2:
/* USER user@host command */ /* USER user@host command */
if (ctxt->user == NULL) if (ctxt->user == NULL)
@ -1164,6 +1160,7 @@ xmlNanoFTPConnect(void *ctx) {
ctxt->controlFd = INVALID_SOCKET; ctxt->controlFd = INVALID_SOCKET;
return(-1); return(-1);
} }
/* Falls through. */
case 3: case 3:
/* /*
* If you need support for other Proxy authentication scheme * If you need support for other Proxy authentication scheme
@ -1212,6 +1209,7 @@ xmlNanoFTPConnect(void *ctx) {
case 3: case 3:
__xmlIOErr(XML_FROM_FTP, XML_FTP_ACCNT, __xmlIOErr(XML_FROM_FTP, XML_FTP_ACCNT,
"FTP server asking for ACCNT on anonymous\n"); "FTP server asking for ACCNT on anonymous\n");
/* Falls through. */
case 1: case 1:
case 4: case 4:
case 5: case 5:

View file

@ -11,7 +11,6 @@
* daniel@veillard.com * daniel@veillard.com
*/ */
#define NEED_SOCKETS
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
@ -74,14 +73,8 @@
#define XML_SOCKLEN_T unsigned int #define XML_SOCKLEN_T unsigned int
#endif #endif
#if defined(__MINGW32__) || defined(_WIN32_WCE) #if defined(_WIN32) && !defined(__CYGWIN__)
/*#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#endif*/
#include <wsockcompat.h> #include <wsockcompat.h>
#include <winsock2.h>
#undef XML_SOCKLEN_T
#define XML_SOCKLEN_T unsigned int
#endif #endif
#include <libxml/globals.h> #include <libxml/globals.h>
@ -182,7 +175,21 @@ xmlHTTPErrMemory(const char *extra)
*/ */
static int socket_errno(void) { static int socket_errno(void) {
#ifdef _WINSOCKAPI_ #ifdef _WINSOCKAPI_
return(WSAGetLastError()); int err = WSAGetLastError();
switch(err) {
case WSAECONNRESET:
return(ECONNRESET);
case WSAEINPROGRESS:
return(EINPROGRESS);
case WSAEINTR:
return(EINTR);
case WSAESHUTDOWN:
return(ESHUTDOWN);
case WSAEWOULDBLOCK:
return(EWOULDBLOCK);
default:
return(err);
}
#else #else
return(errno); return(errno);
#endif #endif
@ -629,7 +636,7 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1) if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
#if defined(EINTR) #if defined(EINTR)
&& (errno != EINTR) && (socket_errno() != EINTR)
#endif #endif
) )
return (0); return (0);
@ -1038,16 +1045,13 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
static SOCKET static SOCKET
xmlNanoHTTPConnectHost(const char *host, int port) xmlNanoHTTPConnectHost(const char *host, int port)
{ {
struct hostent *h;
struct sockaddr *addr = NULL; struct sockaddr *addr = NULL;
struct in_addr ia;
struct sockaddr_in sockin; struct sockaddr_in sockin;
#ifdef SUPPORT_IP6 #ifdef SUPPORT_IP6
struct in6_addr ia6; struct in6_addr ia6;
struct sockaddr_in6 sockin6; struct sockaddr_in6 sockin6;
#endif #endif
int i;
SOCKET s; SOCKET s;
memset (&sockin, 0, sizeof(sockin)); memset (&sockin, 0, sizeof(sockin));
@ -1084,7 +1088,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
for (res = result; res; res = res->ai_next) { for (res = result; res; res = res->ai_next) {
if (res->ai_family == AF_INET) { if (res->ai_family == AF_INET) {
if (res->ai_addrlen > sizeof(sockin)) { if ((size_t)res->ai_addrlen > sizeof(sockin)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
freeaddrinfo (result); freeaddrinfo (result);
return INVALID_SOCKET; return INVALID_SOCKET;
@ -1094,7 +1098,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
addr = (struct sockaddr *)&sockin; addr = (struct sockaddr *)&sockin;
#ifdef SUPPORT_IP6 #ifdef SUPPORT_IP6
} else if (have_ipv6 () && (res->ai_family == AF_INET6)) { } else if (have_ipv6 () && (res->ai_family == AF_INET6)) {
if (res->ai_addrlen > sizeof(sockin6)) { if ((size_t)res->ai_addrlen > sizeof(sockin6)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
freeaddrinfo (result); freeaddrinfo (result);
return INVALID_SOCKET; return INVALID_SOCKET;
@ -1122,6 +1126,10 @@ xmlNanoHTTPConnectHost(const char *host, int port)
#endif #endif
#if !defined(HAVE_GETADDRINFO) || !defined(_WIN32) #if !defined(HAVE_GETADDRINFO) || !defined(_WIN32)
{ {
struct hostent *h;
struct in_addr ia;
int i;
h = gethostbyname (GETHOSTBYNAME_ARG_CAST host); h = gethostbyname (GETHOSTBYNAME_ARG_CAST host);
if (h == NULL) { if (h == NULL) {
@ -1130,7 +1138,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
* extraction code. it work on Linux, if it work on your platform * extraction code. it work on Linux, if it work on your platform
* and one want to enable it, send me the defined(foobar) needed * and one want to enable it, send me the defined(foobar) needed
*/ */
#if defined(HAVE_NETDB_H) && defined(HOST_NOT_FOUND) && defined(linux) #if defined(HAVE_NETDB_H) && defined(HOST_NOT_FOUND) && defined(__linux__)
const char *h_err_txt = ""; const char *h_err_txt = "";
switch (h_errno) { switch (h_errno) {
@ -1423,9 +1431,9 @@ retry:
if (ctxt->port != 80) { if (ctxt->port != 80) {
/* reserve space for ':xxxxx', incl. potential proxy */ /* reserve space for ':xxxxx', incl. potential proxy */
if (proxy) if (proxy)
blen += 12; blen += 17;
else else
blen += 6; blen += 11;
} }
bp = (char*)xmlMallocAtomic(blen); bp = (char*)xmlMallocAtomic(blen);
if ( bp == NULL ) { if ( bp == NULL ) {
@ -1534,7 +1542,8 @@ retry:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"\nRedirect to: %s\n", ctxt->location); "\nRedirect to: %s\n", ctxt->location);
#endif #endif
while ( xmlNanoHTTPRecv(ctxt) > 0 ) ; while ( xmlNanoHTTPRecv(ctxt) > 0 )
;
if (nbRedirects < XML_NANO_HTTP_MAX_REDIR) { if (nbRedirects < XML_NANO_HTTP_MAX_REDIR) {
nbRedirects++; nbRedirects++;
if (redirURL != NULL) if (redirURL != NULL)

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
#if defined(WIN32) && !defined (__CYGWIN__) #if defined(_WIN32) && !defined (__CYGWIN__)
#define XML_DIR_SEP '\\' #define XML_DIR_SEP '\\'
#else #else
#define XML_DIR_SEP '/' #define XML_DIR_SEP '/'
@ -435,8 +435,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
if ((*ctxt->input->cur == 0) && if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) { (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
if ((ctxt->instate != XML_PARSER_COMMENT))
xmlPopInput(ctxt);
return; return;
} }
@ -470,8 +468,8 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
c = *cur; c = *cur;
if (c & 0x80) { if (c & 0x80) {
if (c == 0xC0) if (c == 0xC0)
goto encoding_error; goto encoding_error;
if (cur[1] == 0) { if (cur[1] == 0) {
xmlParserInputGrow(ctxt->input, INPUT_CHUNK); xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
cur = ctxt->input->cur; cur = ctxt->input->cur;
@ -523,8 +521,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
ctxt->input->cur++; ctxt->input->cur++;
ctxt->nbChars++; ctxt->nbChars++;
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
} else { } else {
/* /*
* Assume it's a fixed length encoding (1) with * Assume it's a fixed length encoding (1) with
@ -538,14 +534,9 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
ctxt->input->col++; ctxt->input->col++;
ctxt->input->cur++; ctxt->input->cur++;
ctxt->nbChars++; ctxt->nbChars++;
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
} }
if ((*ctxt->input->cur == '%') && (!ctxt->html)) if (*ctxt->input->cur == 0)
xmlParserHandlePEReference(ctxt); xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
xmlPopInput(ctxt);
return; return;
encoding_error: encoding_error:
/* /*
@ -1101,8 +1092,15 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
break; break;
} }
} }
if (handler == NULL) /*
* TODO: We could recover from errors in external entites if we
* didn't stop the parser. But most callers of this function don't
* check the return value.
*/
if (handler == NULL) {
xmlStopParser(ctxt);
return(-1); return(-1);
}
ctxt->charset = XML_CHAR_ENCODING_UTF8; ctxt->charset = XML_CHAR_ENCODING_UTF8;
ret = xmlSwitchToEncodingInt(ctxt, handler, len); ret = xmlSwitchToEncodingInt(ctxt, handler, len);
if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) { if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
@ -1226,6 +1224,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
*/ */
nbchars = xmlCharEncFirstLineInput(input->buf, len); nbchars = xmlCharEncFirstLineInput(input->buf, len);
} }
xmlBufResetInput(input->buf->buffer, input);
if (nbchars < 0) { if (nbchars < 0) {
xmlErrInternal(ctxt, xmlErrInternal(ctxt,
"switching encoding: encoder error\n", "switching encoding: encoder error\n",
@ -1233,7 +1232,6 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
return (-1); return (-1);
} }
input->buf->rawconsumed += use - xmlBufUse(input->buf->raw); input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
xmlBufResetInput(input->buf->buffer, input);
} }
return (0); return (0);
} else if (input->length == 0) { } else if (input->length == 0) {

View file

@ -969,6 +969,7 @@ xmlCompileAttributeTest(xmlPatParserContextPtr ctxt) {
ERROR5(NULL, NULL, NULL, ERROR5(NULL, NULL, NULL,
"xmlCompileAttributeTest : no namespace bound to prefix %s\n", "xmlCompileAttributeTest : no namespace bound to prefix %s\n",
prefix); prefix);
XML_PAT_FREE_STRING(ctxt, prefix);
ctxt->error = 1; ctxt->error = 1;
goto error; goto error;
} }

View file

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stddef.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/parserInternals.h> #include <libxml/parserInternals.h>
@ -4404,7 +4405,7 @@ xmlRelaxNGComputeInterleaves(xmlRelaxNGDefinePtr def,
if ((*tmp)->type == XML_RELAXNG_TEXT) { if ((*tmp)->type == XML_RELAXNG_TEXT) {
res = xmlHashAddEntry2(partitions->triage, res = xmlHashAddEntry2(partitions->triage,
BAD_CAST "#text", NULL, BAD_CAST "#text", NULL,
(void *) (long) (i + 1)); (void *) (ptrdiff_t) (i + 1));
if (res != 0) if (res != 0)
is_determinist = -1; is_determinist = -1;
} else if (((*tmp)->type == XML_RELAXNG_ELEMENT) && } else if (((*tmp)->type == XML_RELAXNG_ELEMENT) &&
@ -4412,22 +4413,22 @@ xmlRelaxNGComputeInterleaves(xmlRelaxNGDefinePtr def,
if (((*tmp)->ns == NULL) || ((*tmp)->ns[0] == 0)) if (((*tmp)->ns == NULL) || ((*tmp)->ns[0] == 0))
res = xmlHashAddEntry2(partitions->triage, res = xmlHashAddEntry2(partitions->triage,
(*tmp)->name, NULL, (*tmp)->name, NULL,
(void *) (long) (i + 1)); (void *) (ptrdiff_t) (i + 1));
else else
res = xmlHashAddEntry2(partitions->triage, res = xmlHashAddEntry2(partitions->triage,
(*tmp)->name, (*tmp)->ns, (*tmp)->name, (*tmp)->ns,
(void *) (long) (i + 1)); (void *) (ptrdiff_t) (i + 1));
if (res != 0) if (res != 0)
is_determinist = -1; is_determinist = -1;
} else if ((*tmp)->type == XML_RELAXNG_ELEMENT) { } else if ((*tmp)->type == XML_RELAXNG_ELEMENT) {
if (((*tmp)->ns == NULL) || ((*tmp)->ns[0] == 0)) if (((*tmp)->ns == NULL) || ((*tmp)->ns[0] == 0))
res = xmlHashAddEntry2(partitions->triage, res = xmlHashAddEntry2(partitions->triage,
BAD_CAST "#any", NULL, BAD_CAST "#any", NULL,
(void *) (long) (i + 1)); (void *) (ptrdiff_t) (i + 1));
else else
res = xmlHashAddEntry2(partitions->triage, res = xmlHashAddEntry2(partitions->triage,
BAD_CAST "#any", (*tmp)->ns, BAD_CAST "#any", (*tmp)->ns,
(void *) (long) (i + 1)); (void *) (ptrdiff_t) (i + 1));
if ((*tmp)->nameClass != NULL) if ((*tmp)->nameClass != NULL)
is_determinist = 2; is_determinist = 2;
if (res != 0) if (res != 0)
@ -8890,7 +8891,7 @@ xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
if (ret != 0) { if (ret != 0) {
break; break;
} }
/* no break on purpose */ /* Falls through. */
case XML_RELAXNG_ZEROORMORE:{ case XML_RELAXNG_ZEROORMORE:{
xmlChar *cur, *temp; xmlChar *cur, *temp;
@ -9387,7 +9388,7 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
if (tmp == NULL) { if (tmp == NULL) {
i = nbgroups; i = nbgroups;
} else { } else {
i = ((long) tmp) - 1; i = ((ptrdiff_t) tmp) - 1;
if (partitions->flags & IS_NEEDCHECK) { if (partitions->flags & IS_NEEDCHECK) {
group = partitions->groups[i]; group = partitions->groups[i];
if (!xmlRelaxNGNodeMatchesList(cur, group->defs)) if (!xmlRelaxNGNodeMatchesList(cur, group->defs))
@ -10167,7 +10168,7 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
} }
if (ctxt->errNr > errNr) if (ctxt->errNr > errNr)
xmlRelaxNGPopErrors(ctxt, errNr); xmlRelaxNGPopErrors(ctxt, errNr);
/* no break on purpose */ /* Falls through. */
case XML_RELAXNG_ZEROORMORE:{ case XML_RELAXNG_ZEROORMORE:{
int progress; int progress;
xmlRelaxNGStatesPtr states = NULL, res = NULL; xmlRelaxNGStatesPtr states = NULL, res = NULL;

View file

@ -27,6 +27,7 @@
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
#include <pthread.h> #include <pthread.h>
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h> //#include <windows.h>
#ifndef HAVE_COMPILER_TLS #ifndef HAVE_COMPILER_TLS
#include <process.h> #include <process.h>
@ -48,47 +49,27 @@
static int libxml_is_threaded = -1; static int libxml_is_threaded = -1;
#if defined(__GNUC__) && defined(__GLIBC__) #if defined(__GNUC__) && defined(__GLIBC__)
#ifdef linux #ifdef __linux__
#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3) #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3)
extern int pthread_once (pthread_once_t *__once_control, #pragma weak pthread_once
void (*__init_routine) (void)) #pragma weak pthread_getspecific
__attribute((weak)); #pragma weak pthread_setspecific
extern void *pthread_getspecific (pthread_key_t __key) #pragma weak pthread_key_create
__attribute((weak)); #pragma weak pthread_key_delete
extern int pthread_setspecific (pthread_key_t __key, #pragma weak pthread_mutex_init
__const void *__pointer) #pragma weak pthread_mutex_destroy
__attribute((weak)); #pragma weak pthread_mutex_lock
extern int pthread_key_create (pthread_key_t *__key, #pragma weak pthread_mutex_unlock
void (*__destr_function) (void *)) #pragma weak pthread_cond_init
__attribute((weak)); #pragma weak pthread_cond_destroy
extern int pthread_key_delete (pthread_key_t __key) #pragma weak pthread_cond_wait
__attribute((weak)); #pragma weak pthread_equal
extern int pthread_mutex_init () #pragma weak pthread_self
__attribute((weak)); #pragma weak pthread_key_create
extern int pthread_mutex_destroy () #pragma weak pthread_key_delete
__attribute((weak)); #pragma weak pthread_cond_signal
extern int pthread_mutex_lock ()
__attribute((weak));
extern int pthread_mutex_unlock ()
__attribute((weak));
extern int pthread_cond_init ()
__attribute((weak));
extern int pthread_cond_destroy ()
__attribute((weak));
extern int pthread_cond_wait ()
__attribute((weak));
extern int pthread_equal ()
__attribute((weak));
extern pthread_t pthread_self ()
__attribute((weak));
extern int pthread_key_create ()
__attribute((weak));
extern int pthread_key_delete ()
__attribute((weak));
extern int pthread_cond_signal ()
__attribute((weak));
#endif #endif
#endif /* linux */ #endif /* __linux__ */
#endif /* defined(__GNUC__) && defined(__GLIBC__) */ #endif /* defined(__GNUC__) && defined(__GLIBC__) */
#endif /* HAVE_PTHREAD_H */ #endif /* HAVE_PTHREAD_H */
@ -158,7 +139,7 @@ static DWORD globalkey = TLS_OUT_OF_INDEXES;
static DWORD mainthread; static DWORD mainthread;
static struct { static struct {
DWORD done; DWORD done;
DWORD control; LONG control;
} run_once = { 0, 0}; } run_once = { 0, 0};
static volatile LPCRITICAL_SECTION global_init_lock = NULL; static volatile LPCRITICAL_SECTION global_init_lock = NULL;
@ -458,7 +439,8 @@ __xmlGlobalInitMutexLock(void)
/* Swap it into the global_init_lock */ /* Swap it into the global_init_lock */
#ifdef InterlockedCompareExchangePointer #ifdef InterlockedCompareExchangePointer
InterlockedCompareExchangePointer(&global_init_lock, cs, NULL); InterlockedCompareExchangePointer((void **) &global_init_lock,
cs, NULL);
#else /* Use older void* version */ #else /* Use older void* version */
InterlockedCompareExchange((void **) &global_init_lock, InterlockedCompareExchange((void **) &global_init_lock,
(void *) cs, NULL); (void *) cs, NULL);
@ -999,11 +981,23 @@ xmlOnceInit(void)
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)) #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
#if defined(LIBXML_STATIC_FOR_DLL) #if defined(LIBXML_STATIC_FOR_DLL)
BOOL XMLCALL int XMLCALL
xmlDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) xmlDllMain(ATTRIBUTE_UNUSED void *hinstDLL, unsigned long fdwReason,
ATTRIBUTE_UNUSED void *lpvReserved)
#else #else
/* declare to avoid "no previous prototype for 'DllMain'" warning */
/* Note that we do NOT want to include this function declaration in
a public header because it's meant to be called by Windows itself,
not a program that uses this library. This also has to be exported. */
XMLPUBFUN BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved);
BOOL WINAPI BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) DllMain(ATTRIBUTE_UNUSED HINSTANCE hinstDLL, DWORD fdwReason,
ATTRIBUTE_UNUSED LPVOID lpvReserved)
#endif #endif
{ {
switch (fdwReason) { switch (fdwReason) {

View file

@ -1,90 +1,44 @@
/* /*
* taken from https://github.com/swenson/sort * Taken from https://github.com/swenson/sort
* Kept as is for the moment to be able to apply upstream patches for that * Revision: 05fd77bfec049ce8b7c408c4d3dd2d51ee061a15
* code, currently used only to speed up XPath node sorting, see xpath.c * Removed all code unrelated to Timsort and made minor adjustments for
* cross-platform compatibility.
*/ */
/* /*
* All code in this header, unless otherwise specified, is hereby licensed under the MIT Public License: * The MIT License (MIT)
*
Copyright (c) 2010 Christopher Swenson * Copyright (c) 2010-2017 Christopher Swenson.
* Copyright (c) 2012 Vojtech Fried.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * Copyright (c) 2012 Google Inc. All Rights Reserved.
*
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * to deal in the Software without restriction, including without limitation
*/ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef HAVE_STDINT_H #ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #elif defined(_WIN32)
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#elif defined(WIN32)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
#endif #endif
#endif
#ifndef MK_UINT64
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER < 1300
#define MK_UINT64(x) ((uint64_t)(x))
#else
#define MK_UINT64(x) x##ULL
#endif
#endif
#ifndef MAX
#define MAX(x,y) (((x) > (y) ? (x) : (y)))
#endif
#ifndef MIN
#define MIN(x,y) (((x) < (y) ? (x) : (y)))
#endif
int compute_minrun(uint64_t);
#ifndef CLZ
#if defined(__GNUC__) && ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ > 3))
#define CLZ __builtin_clzll
#else
int clzll(uint64_t);
/* adapted from Hacker's Delight */
int clzll(uint64_t x) /* {{{ */
{
int n;
if (x == 0) return(64);
n = 0;
if (x <= MK_UINT64(0x00000000FFFFFFFF)) {n = n + 32; x = x << 32;}
if (x <= MK_UINT64(0x0000FFFFFFFFFFFF)) {n = n + 16; x = x << 16;}
if (x <= MK_UINT64(0x00FFFFFFFFFFFFFF)) {n = n + 8; x = x << 8;}
if (x <= MK_UINT64(0x0FFFFFFFFFFFFFFF)) {n = n + 4; x = x << 4;}
if (x <= MK_UINT64(0x3FFFFFFFFFFFFFFF)) {n = n + 2; x = x << 2;}
if (x <= MK_UINT64(0x7FFFFFFFFFFFFFFF)) {n = n + 1;}
return n;
}
/* }}} */
#define CLZ clzll
#endif
#endif
int compute_minrun(uint64_t size) /* {{{ */
{
const int top_bit = 64 - CLZ(size);
const int shift = MAX(top_bit, 6) - 6;
const int minrun = size >> shift;
const uint64_t mask = (MK_UINT64(1) << shift) - 1;
if (mask & size) return minrun + 1;
return minrun;
}
/* }}} */
#ifndef SORT_NAME #ifndef SORT_NAME
#error "Must declare SORT_NAME" #error "Must declare SORT_NAME"
@ -98,215 +52,299 @@ int compute_minrun(uint64_t size) /* {{{ */
#define SORT_CMP(x, y) ((x) < (y) ? -1 : ((x) == (y) ? 0 : 1)) #define SORT_CMP(x, y) ((x) < (y) ? -1 : ((x) == (y) ? 0 : 1))
#endif #endif
#ifndef TIM_SORT_STACK_SIZE
#define TIM_SORT_STACK_SIZE 128
#endif
#define SORT_SWAP(x,y) {SORT_TYPE __SORT_SWAP_t = (x); (x) = (y); (y) = __SORT_SWAP_t;} #define SORT_SWAP(x,y) {SORT_TYPE __SORT_SWAP_t = (x); (x) = (y); (y) = __SORT_SWAP_t;}
/* Common, type-agnosting functions and constants that we don't want to declare twice. */
#ifndef SORT_COMMON_H
#define SORT_COMMON_H
#ifndef MAX
#define MAX(x,y) (((x) > (y) ? (x) : (y)))
#endif
#ifndef MIN
#define MIN(x,y) (((x) < (y) ? (x) : (y)))
#endif
static int compute_minrun(const uint64_t);
#ifndef CLZ
#ifdef __GNUC__
#define CLZ __builtin_clzll
#else
static int clzll(uint64_t);
/* adapted from Hacker's Delight */
static int clzll(uint64_t x) {
int n;
if (x == 0) {
return 64;
}
n = 0;
if (x <= 0x00000000FFFFFFFFL) {
n = n + 32;
x = x << 32;
}
if (x <= 0x0000FFFFFFFFFFFFL) {
n = n + 16;
x = x << 16;
}
if (x <= 0x00FFFFFFFFFFFFFFL) {
n = n + 8;
x = x << 8;
}
if (x <= 0x0FFFFFFFFFFFFFFFL) {
n = n + 4;
x = x << 4;
}
if (x <= 0x3FFFFFFFFFFFFFFFL) {
n = n + 2;
x = x << 2;
}
if (x <= 0x7FFFFFFFFFFFFFFFL) {
n = n + 1;
}
return n;
}
#define CLZ clzll
#endif
#endif
static __inline int compute_minrun(const uint64_t size) {
const int top_bit = 64 - CLZ(size);
const int shift = MAX(top_bit, 6) - 6;
const int minrun = size >> shift;
const uint64_t mask = (1ULL << shift) - 1;
if (mask & size) {
return minrun + 1;
}
return minrun;
}
#endif /* SORT_COMMON_H */
#define SORT_CONCAT(x, y) x ## _ ## y #define SORT_CONCAT(x, y) x ## _ ## y
#define SORT_MAKE_STR1(x, y) SORT_CONCAT(x,y) #define SORT_MAKE_STR1(x, y) SORT_CONCAT(x,y)
#define SORT_MAKE_STR(x) SORT_MAKE_STR1(SORT_NAME,x) #define SORT_MAKE_STR(x) SORT_MAKE_STR1(SORT_NAME,x)
#define BINARY_INSERTION_FIND SORT_MAKE_STR(binary_insertion_find) #define BINARY_INSERTION_FIND SORT_MAKE_STR(binary_insertion_find)
#define BINARY_INSERTION_SORT_START SORT_MAKE_STR(binary_insertion_sort_start) #define BINARY_INSERTION_SORT_START SORT_MAKE_STR(binary_insertion_sort_start)
#define BINARY_INSERTION_SORT SORT_MAKE_STR(binary_insertion_sort) #define BINARY_INSERTION_SORT SORT_MAKE_STR(binary_insertion_sort)
#define REVERSE_ELEMENTS SORT_MAKE_STR(reverse_elements) #define REVERSE_ELEMENTS SORT_MAKE_STR(reverse_elements)
#define COUNT_RUN SORT_MAKE_STR(count_run) #define COUNT_RUN SORT_MAKE_STR(count_run)
#define CHECK_INVARIANT SORT_MAKE_STR(check_invariant) #define CHECK_INVARIANT SORT_MAKE_STR(check_invariant)
#define TIM_SORT SORT_MAKE_STR(tim_sort) #define TIM_SORT SORT_MAKE_STR(tim_sort)
#define TIM_SORT_RESIZE SORT_MAKE_STR(tim_sort_resize) #define TIM_SORT_RESIZE SORT_MAKE_STR(tim_sort_resize)
#define TIM_SORT_MERGE SORT_MAKE_STR(tim_sort_merge) #define TIM_SORT_MERGE SORT_MAKE_STR(tim_sort_merge)
#define TIM_SORT_COLLAPSE SORT_MAKE_STR(tim_sort_collapse) #define TIM_SORT_COLLAPSE SORT_MAKE_STR(tim_sort_collapse)
#define TIM_SORT_RUN_T SORT_MAKE_STR(tim_sort_run_t) #ifndef MAX
#define TEMP_STORAGE_T SORT_MAKE_STR(temp_storage_t) #define MAX(x,y) (((x) > (y) ? (x) : (y)))
#endif
#ifndef MIN
#define MIN(x,y) (((x) < (y) ? (x) : (y)))
#endif
typedef struct { typedef struct {
int64_t start; size_t start;
int64_t length; size_t length;
} TIM_SORT_RUN_T; } TIM_SORT_RUN_T;
void BINARY_INSERTION_SORT(SORT_TYPE *dst, const size_t size); void BINARY_INSERTION_SORT(SORT_TYPE *dst, const size_t size);
void TIM_SORT(SORT_TYPE *dst, const size_t size); void TIM_SORT(SORT_TYPE *dst, const size_t size);
/* Function used to do a binary search for binary insertion sort */ /* Function used to do a binary search for binary insertion sort */
static int64_t BINARY_INSERTION_FIND(SORT_TYPE *dst, const SORT_TYPE x, const size_t size) static __inline size_t BINARY_INSERTION_FIND(SORT_TYPE *dst, const SORT_TYPE x,
{ const size_t size) {
int64_t l, c, r; size_t l, c, r;
SORT_TYPE lx;
SORT_TYPE cx; SORT_TYPE cx;
l = 0; l = 0;
r = size - 1; r = size - 1;
c = r >> 1; c = r >> 1;
lx = dst[l];
/* check for beginning conditions */ /* check for out of bounds at the beginning. */
if (SORT_CMP(x, lx) < 0) if (SORT_CMP(x, dst[0]) < 0) {
return 0; return 0;
else if (SORT_CMP(x, lx) == 0) } else if (SORT_CMP(x, dst[r]) > 0) {
{ return r;
int64_t i = 1;
while (SORT_CMP(x, dst[i]) == 0) i++;
return i;
} }
cx = dst[c]; cx = dst[c];
while (1)
{ while (1) {
const int val = SORT_CMP(x, cx); const int val = SORT_CMP(x, cx);
if (val < 0)
{ if (val < 0) {
if (c - l <= 1) return c; if (c - l <= 1) {
return c;
}
r = c; r = c;
} } else { /* allow = for stability. The binary search favors the right. */
else if (val > 0) if (r - c <= 1) {
{ return c + 1;
if (r - c <= 1) return c + 1; }
l = c; l = c;
lx = cx;
}
else
{
do
{
cx = dst[++c];
} while (SORT_CMP(x, cx) == 0);
return c;
} }
c = l + ((r - l) >> 1); c = l + ((r - l) >> 1);
cx = dst[c]; cx = dst[c];
} }
} }
/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */ /* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */
static void BINARY_INSERTION_SORT_START(SORT_TYPE *dst, const size_t start, const size_t size) static void BINARY_INSERTION_SORT_START(SORT_TYPE *dst, const size_t start, const size_t size) {
{ size_t i;
int64_t i;
for (i = start; i < (int64_t) size; i++) for (i = start; i < size; i++) {
{ size_t j;
int64_t j;
SORT_TYPE x; SORT_TYPE x;
int64_t location; size_t location;
/* If this entry is already correct, just move along */ /* If this entry is already correct, just move along */
if (SORT_CMP(dst[i - 1], dst[i]) <= 0) continue; if (SORT_CMP(dst[i - 1], dst[i]) <= 0) {
continue;
}
/* Else we need to find the right place, shift everything over, and squeeze in */ /* Else we need to find the right place, shift everything over, and squeeze in */
x = dst[i]; x = dst[i];
location = BINARY_INSERTION_FIND(dst, x, i); location = BINARY_INSERTION_FIND(dst, x, i);
for (j = i - 1; j >= location; j--)
{ for (j = i - 1; j >= location; j--) {
dst[j + 1] = dst[j]; dst[j + 1] = dst[j];
if (j == 0) { /* check edge case because j is unsigned */
break;
}
} }
dst[location] = x; dst[location] = x;
} }
} }
/* Binary insertion sort */ /* Binary insertion sort */
void BINARY_INSERTION_SORT(SORT_TYPE *dst, const size_t size) void BINARY_INSERTION_SORT(SORT_TYPE *dst, const size_t size) {
{ /* don't bother sorting an array of size <= 1 */
if (size <= 1) {
return;
}
BINARY_INSERTION_SORT_START(dst, 1, size); BINARY_INSERTION_SORT_START(dst, 1, size);
} }
/* timsort implementation, based on timsort.txt */ /* timsort implementation, based on timsort.txt */
static void REVERSE_ELEMENTS(SORT_TYPE *dst, int64_t start, int64_t end) static __inline void REVERSE_ELEMENTS(SORT_TYPE *dst, size_t start, size_t end) {
{ while (1) {
while (1) if (start >= end) {
{ return;
if (start >= end) return; }
SORT_SWAP(dst[start], dst[end]); SORT_SWAP(dst[start], dst[end]);
start++; start++;
end--; end--;
} }
} }
static int64_t COUNT_RUN(SORT_TYPE *dst, const int64_t start, const size_t size) static size_t COUNT_RUN(SORT_TYPE *dst, const size_t start, const size_t size) {
{ size_t curr;
int64_t curr;
if (size - start == 1) return 1; if (size - start == 1) {
if (start >= (int64_t) size - 2) return 1;
{ }
if (SORT_CMP(dst[size - 2], dst[size - 1]) > 0)
if (start >= size - 2) {
if (SORT_CMP(dst[size - 2], dst[size - 1]) > 0) {
SORT_SWAP(dst[size - 2], dst[size - 1]); SORT_SWAP(dst[size - 2], dst[size - 1]);
}
return 2; return 2;
} }
curr = start + 2; curr = start + 2;
if (SORT_CMP(dst[start], dst[start + 1]) <= 0) if (SORT_CMP(dst[start], dst[start + 1]) <= 0) {
{
/* increasing run */ /* increasing run */
while (1) while (1) {
{ if (curr == size - 1) {
if (curr == (int64_t) size - 1) break; break;
if (SORT_CMP(dst[curr - 1], dst[curr]) > 0) break; }
if (SORT_CMP(dst[curr - 1], dst[curr]) > 0) {
break;
}
curr++; curr++;
} }
return curr - start; return curr - start;
} } else {
else
{
/* decreasing run */ /* decreasing run */
while (1) while (1) {
{ if (curr == size - 1) {
if (curr == (int64_t) size - 1) break; break;
if (SORT_CMP(dst[curr - 1], dst[curr]) <= 0) break; }
if (SORT_CMP(dst[curr - 1], dst[curr]) <= 0) {
break;
}
curr++; curr++;
} }
/* reverse in-place */ /* reverse in-place */
REVERSE_ELEMENTS(dst, start, curr - 1); REVERSE_ELEMENTS(dst, start, curr - 1);
return curr - start; return curr - start;
} }
} }
#define PUSH_NEXT() do {\ static int CHECK_INVARIANT(TIM_SORT_RUN_T *stack, const int stack_curr) {
len = COUNT_RUN(dst, curr, size);\ size_t A, B, C;
run = minrun;\
if (run < minrun) run = minrun;\
if (run > (int64_t) size - curr) run = size - curr;\
if (run > len)\
{\
BINARY_INSERTION_SORT_START(&dst[curr], len, run);\
len = run;\
}\
{\
run_stack[stack_curr].start = curr;\
run_stack[stack_curr].length = len;\
stack_curr++;\
}\
curr += len;\
if (curr == (int64_t) size)\
{\
/* finish up */ \
while (stack_curr > 1) \
{ \
TIM_SORT_MERGE(dst, run_stack, stack_curr, store); \
run_stack[stack_curr - 2].length += run_stack[stack_curr - 1].length; \
stack_curr--; \
} \
if (store->storage != NULL)\
{\
free(store->storage);\
store->storage = NULL;\
}\
return;\
}\
}\
while (0)
static int CHECK_INVARIANT(TIM_SORT_RUN_T *stack, const int stack_curr) if (stack_curr < 2) {
{
int64_t A, B, C;
if (stack_curr < 2) return 1;
if (stack_curr == 2)
{
const int64_t A1 = stack[stack_curr - 2].length;
const int64_t B1 = stack[stack_curr - 1].length;
if (A1 <= B1) return 0;
return 1; return 1;
} }
if (stack_curr == 2) {
const size_t A1 = stack[stack_curr - 2].length;
const size_t B1 = stack[stack_curr - 1].length;
if (A1 <= B1) {
return 0;
}
return 1;
}
A = stack[stack_curr - 3].length; A = stack[stack_curr - 3].length;
B = stack[stack_curr - 2].length; B = stack[stack_curr - 2].length;
C = stack[stack_curr - 1].length; C = stack[stack_curr - 1].length;
if ((A <= B + C) || (B <= C)) return 0;
if ((A <= B + C) || (B <= C)) {
return 0;
}
return 1; return 1;
} }
@ -315,86 +353,78 @@ typedef struct {
SORT_TYPE *storage; SORT_TYPE *storage;
} TEMP_STORAGE_T; } TEMP_STORAGE_T;
static void TIM_SORT_RESIZE(TEMP_STORAGE_T *store, const size_t new_size) {
static void TIM_SORT_RESIZE(TEMP_STORAGE_T *store, const size_t new_size) if (store->alloc < new_size) {
{
if (store->alloc < new_size)
{
SORT_TYPE *tempstore = (SORT_TYPE *)realloc(store->storage, new_size * sizeof(SORT_TYPE)); SORT_TYPE *tempstore = (SORT_TYPE *)realloc(store->storage, new_size * sizeof(SORT_TYPE));
if (tempstore == NULL)
{ if (tempstore == NULL) {
fprintf(stderr, "Error allocating temporary storage for tim sort: need %lu bytes", sizeof(SORT_TYPE) * new_size); fprintf(stderr, "Error allocating temporary storage for tim sort: need %lu bytes",
(unsigned long)(sizeof(SORT_TYPE) * new_size));
exit(1); exit(1);
} }
store->storage = tempstore; store->storage = tempstore;
store->alloc = new_size; store->alloc = new_size;
} }
} }
static void TIM_SORT_MERGE(SORT_TYPE *dst, const TIM_SORT_RUN_T *stack, const int stack_curr, TEMP_STORAGE_T *store) static void TIM_SORT_MERGE(SORT_TYPE *dst, const TIM_SORT_RUN_T *stack, const int stack_curr,
{ TEMP_STORAGE_T *store) {
const int64_t A = stack[stack_curr - 2].length; const size_t A = stack[stack_curr - 2].length;
const int64_t B = stack[stack_curr - 1].length; const size_t B = stack[stack_curr - 1].length;
const int64_t curr = stack[stack_curr - 2].start; const size_t curr = stack[stack_curr - 2].start;
SORT_TYPE *storage; SORT_TYPE *storage;
int64_t i, j, k; size_t i, j, k;
TIM_SORT_RESIZE(store, MIN(A, B)); TIM_SORT_RESIZE(store, MIN(A, B));
storage = store->storage; storage = store->storage;
/* left merge */ /* left merge */
if (A < B) if (A < B) {
{
memcpy(storage, &dst[curr], A * sizeof(SORT_TYPE)); memcpy(storage, &dst[curr], A * sizeof(SORT_TYPE));
i = 0; i = 0;
j = curr + A; j = curr + A;
for (k = curr; k < curr + A + B; k++) for (k = curr; k < curr + A + B; k++) {
{ if ((i < A) && (j < curr + A + B)) {
if ((i < A) && (j < curr + A + B)) if (SORT_CMP(storage[i], dst[j]) <= 0) {
{
if (SORT_CMP(storage[i], dst[j]) <= 0)
dst[k] = storage[i++]; dst[k] = storage[i++];
else } else {
dst[k] = dst[j++]; dst[k] = dst[j++];
} }
else if (i < A) } else if (i < A) {
{
dst[k] = storage[i++]; dst[k] = storage[i++];
} else {
break;
} }
else
dst[k] = dst[j++];
} }
} } else {
/* right merge */ /* right merge */
else
{
memcpy(storage, &dst[curr + A], B * sizeof(SORT_TYPE)); memcpy(storage, &dst[curr + A], B * sizeof(SORT_TYPE));
i = B - 1; i = B;
j = curr + A - 1; j = curr + A;
k = curr + A + B;
for (k = curr + A + B - 1; k >= curr; k--) while (k-- > curr) {
{ if ((i > 0) && (j > curr)) {
if ((i >= 0) && (j >= curr)) if (SORT_CMP(dst[j - 1], storage[i - 1]) > 0) {
{ dst[k] = dst[--j];
if (SORT_CMP(dst[j], storage[i]) > 0) } else {
dst[k] = dst[j--]; dst[k] = storage[--i];
else }
dst[k] = storage[i--]; } else if (i > 0) {
dst[k] = storage[--i];
} else {
break;
} }
else if (i >= 0)
dst[k] = storage[i--];
else
dst[k] = dst[j--];
} }
} }
} }
static int TIM_SORT_COLLAPSE(SORT_TYPE *dst, TIM_SORT_RUN_T *stack, int stack_curr, TEMP_STORAGE_T *store, const size_t size) static int TIM_SORT_COLLAPSE(SORT_TYPE *dst, TIM_SORT_RUN_T *stack, int stack_curr,
{ TEMP_STORAGE_T *store, const size_t size) {
while (1) { while (1) {
int64_t A, B, C, D; size_t A, B, C, D;
int ABC, BCD, BD, CD; int ABC, BCD, CD;
/* if the stack only has one thing on it, we are done with the collapse */ /* if the stack only has one thing on it, we are done with the collapse */
if (stack_curr <= 1) { if (stack_curr <= 1) {
@ -431,7 +461,6 @@ static int TIM_SORT_COLLAPSE(SORT_TYPE *dst, TIM_SORT_RUN_T *stack, int stack_cu
BCD = (B <= C + D) || ABC; BCD = (B <= C + D) || ABC;
CD = (C <= D); CD = (C <= D);
BD = (B < D);
/* Both invariants are good */ /* Both invariants are good */
if (!BCD && !CD) { if (!BCD && !CD) {
@ -455,41 +484,94 @@ static int TIM_SORT_COLLAPSE(SORT_TYPE *dst, TIM_SORT_RUN_T *stack, int stack_cu
return stack_curr; return stack_curr;
} }
void TIM_SORT(SORT_TYPE *dst, const size_t size) static __inline int PUSH_NEXT(SORT_TYPE *dst,
{ const size_t size,
int minrun; TEMP_STORAGE_T *store,
TEMP_STORAGE_T _store, *store; const size_t minrun,
TIM_SORT_RUN_T run_stack[128]; TIM_SORT_RUN_T *run_stack,
int stack_curr = 0; size_t *stack_curr,
int64_t len, run; size_t *curr) {
int64_t curr = 0; size_t len = COUNT_RUN(dst, *curr, size);
size_t run = minrun;
if (size < 64) if (run > size - *curr) {
{ run = size - *curr;
}
if (run > len) {
BINARY_INSERTION_SORT_START(&dst[*curr], len, run);
len = run;
}
run_stack[*stack_curr].start = *curr;
run_stack[*stack_curr].length = len;
(*stack_curr)++;
*curr += len;
if (*curr == size) {
/* finish up */
while (*stack_curr > 1) {
TIM_SORT_MERGE(dst, run_stack, *stack_curr, store);
run_stack[*stack_curr - 2].length += run_stack[*stack_curr - 1].length;
(*stack_curr)--;
}
if (store->storage != NULL) {
free(store->storage);
store->storage = NULL;
}
return 0;
}
return 1;
}
void TIM_SORT(SORT_TYPE *dst, const size_t size) {
size_t minrun;
TEMP_STORAGE_T _store, *store;
TIM_SORT_RUN_T run_stack[TIM_SORT_STACK_SIZE];
size_t stack_curr = 0;
size_t curr = 0;
/* don't bother sorting an array of size 1 */
if (size <= 1) {
return;
}
if (size < 64) {
BINARY_INSERTION_SORT(dst, size); BINARY_INSERTION_SORT(dst, size);
return; return;
} }
/* compute the minimum run length */ /* compute the minimum run length */
minrun = compute_minrun(size); minrun = compute_minrun(size);
/* temporary storage for merges */ /* temporary storage for merges */
store = &_store; store = &_store;
store->alloc = 0; store->alloc = 0;
store->storage = NULL; store->storage = NULL;
PUSH_NEXT(); if (!PUSH_NEXT(dst, size, store, minrun, run_stack, &stack_curr, &curr)) {
PUSH_NEXT(); return;
PUSH_NEXT(); }
while (1) if (!PUSH_NEXT(dst, size, store, minrun, run_stack, &stack_curr, &curr)) {
{ return;
if (!CHECK_INVARIANT(run_stack, stack_curr)) }
{
if (!PUSH_NEXT(dst, size, store, minrun, run_stack, &stack_curr, &curr)) {
return;
}
while (1) {
if (!CHECK_INVARIANT(run_stack, stack_curr)) {
stack_curr = TIM_SORT_COLLAPSE(dst, run_stack, stack_curr, store, size); stack_curr = TIM_SORT_COLLAPSE(dst, run_stack, stack_curr, store, size);
continue; continue;
} }
PUSH_NEXT();
if (!PUSH_NEXT(dst, size, store, minrun, run_stack, &stack_curr, &curr)) {
return;
}
} }
} }

View file

@ -10,10 +10,16 @@
* *
*/ */
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
#include <string.h> /* for memset() only ! */ #include <string.h> /* for memset() only ! */
#include <stddef.h>
#include <limits.h> #include <limits.h>
#ifdef HAVE_CTYPE_H #ifdef HAVE_CTYPE_H
#include <ctype.h> #include <ctype.h>
@ -254,10 +260,10 @@ xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix,
* *
* [NS 7] LocalPart ::= NCName * [NS 7] LocalPart ::= NCName
* *
* Returns NULL if not a QName, otherwise the local part, and prefix * Returns NULL if the name doesn't have a prefix. Otherwise, returns the
* is updated to get the Prefix if any. * local part, and prefix is updated to get the Prefix. Both the return value
* and the prefix must be freed by the caller.
*/ */
xmlChar * xmlChar *
xmlSplitQName2(const xmlChar *name, xmlChar **prefix) { xmlSplitQName2(const xmlChar *name, xmlChar **prefix) {
int len = 0; int len = 0;
@ -1401,6 +1407,8 @@ xmlStringLenGetNodeList(const xmlDoc *doc, const xmlChar *value, int len) {
else if ((ent != NULL) && (ent->children == NULL)) { else if ((ent != NULL) && (ent->children == NULL)) {
xmlNodePtr temp; xmlNodePtr temp;
/* Set to non-NULL value to avoid recursion. */
ent->children = (xmlNodePtr) -1;
ent->children = xmlStringGetNodeList(doc, ent->children = xmlStringGetNodeList(doc,
(const xmlChar*)node->content); (const xmlChar*)node->content);
ent->owner = 1; ent->owner = 1;
@ -1593,6 +1601,7 @@ xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) {
else if ((ent != NULL) && (ent->children == NULL)) { else if ((ent != NULL) && (ent->children == NULL)) {
xmlNodePtr temp; xmlNodePtr temp;
/* Set to non-NULL value to avoid recursion. */
ent->children = (xmlNodePtr) -1; ent->children = (xmlNodePtr) -1;
ent->children = xmlStringGetNodeList(doc, ent->children = xmlStringGetNodeList(doc,
(const xmlChar*)node->content); (const xmlChar*)node->content);
@ -1600,6 +1609,7 @@ xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) {
temp = ent->children; temp = ent->children;
while (temp) { while (temp) {
temp->parent = (xmlNodePtr)ent; temp->parent = (xmlNodePtr)ent;
ent->last = temp;
temp = temp->next; temp = temp->next;
} }
} }
@ -4596,7 +4606,7 @@ xmlGetLineNoInternal(const xmlNode *node, int depth)
(node->type == XML_PI_NODE)) { (node->type == XML_PI_NODE)) {
if (node->line == 65535) { if (node->line == 65535) {
if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL)) if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL))
result = (long) node->psvi; result = (long) (ptrdiff_t) node->psvi;
else if ((node->type == XML_ELEMENT_NODE) && else if ((node->type == XML_ELEMENT_NODE) &&
(node->children != NULL)) (node->children != NULL))
result = xmlGetLineNoInternal(node->children, depth + 1); result = xmlGetLineNoInternal(node->children, depth + 1);
@ -4755,8 +4765,8 @@ xmlGetNodePath(const xmlNode *node)
if (occur == 0) { if (occur == 0) {
tmp = cur->next; tmp = cur->next;
while (tmp != NULL && occur == 0) { while (tmp != NULL && occur == 0) {
if (tmp->type == XML_COMMENT_NODE) if (tmp->type == XML_COMMENT_NODE)
occur++; occur++;
tmp = tmp->next; tmp = tmp->next;
} }
if (occur != 0) if (occur != 0)
@ -8249,7 +8259,7 @@ xmlDOMWrapRemoveNode(xmlDOMWrapCtxtPtr ctxt, xmlDocPtr doc,
ns = ns->next; ns = ns->next;
} while (ns != NULL); } while (ns != NULL);
} }
/* No break on purpose. */ /* Falls through. */
case XML_ATTRIBUTE_NODE: case XML_ATTRIBUTE_NODE:
if (node->ns != NULL) { if (node->ns != NULL) {
/* /*
@ -8840,7 +8850,7 @@ next_ns_decl:
} }
if (! adoptns) if (! adoptns)
goto ns_end; goto ns_end;
/* No break on purpose. */ /* Falls through. */
case XML_ATTRIBUTE_NODE: case XML_ATTRIBUTE_NODE:
/* No ns, no fun. */ /* No ns, no fun. */
if (cur->ns == NULL) if (cur->ns == NULL)
@ -9121,7 +9131,7 @@ xmlDOMWrapAdoptBranch(xmlDOMWrapCtxtPtr ctxt,
goto internal_error; goto internal_error;
} }
} }
/* No break on purpose. */ /* Falls through. */
case XML_ATTRIBUTE_NODE: case XML_ATTRIBUTE_NODE:
/* No namespace, no fun. */ /* No namespace, no fun. */
if (cur->ns == NULL) if (cur->ns == NULL)

View file

@ -327,7 +327,7 @@ trio_nan(TRIO_NOARGS)
if (result == 0.0) { if (result == 0.0) {
#if defined(TRIO_COMPILER_SUPPORTS_C99) && !defined(__clang__) #if defined(TRIO_COMPILER_SUPPORTS_C99)
result = nan(""); result = nan("");
#elif defined(NAN) && defined(__STDC_IEC_559__) #elif defined(NAN) && defined(__STDC_IEC_559__)

View file

@ -1961,8 +1961,9 @@ xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
res->scheme = xmlMemStrdup(bas->scheme); res->scheme = xmlMemStrdup(bas->scheme);
if (bas->authority != NULL) if (bas->authority != NULL)
res->authority = xmlMemStrdup(bas->authority); res->authority = xmlMemStrdup(bas->authority);
else if (bas->server != NULL) { else if ((bas->server != NULL) || (bas->port == -1)) {
res->server = xmlMemStrdup(bas->server); if (bas->server != NULL)
res->server = xmlMemStrdup(bas->server);
if (bas->user != NULL) if (bas->user != NULL)
res->user = xmlMemStrdup(bas->user); res->user = xmlMemStrdup(bas->user);
res->port = bas->port; res->port = bas->port;
@ -2024,8 +2025,9 @@ xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
} }
if (bas->authority != NULL) if (bas->authority != NULL)
res->authority = xmlMemStrdup(bas->authority); res->authority = xmlMemStrdup(bas->authority);
else if (bas->server != NULL) { else if ((bas->server != NULL) || (bas->port == -1)) {
res->server = xmlMemStrdup(bas->server); if (bas->server != NULL)
res->server = xmlMemStrdup(bas->server);
if (bas->user != NULL) if (bas->user != NULL)
res->user = xmlMemStrdup(bas->user); res->user = xmlMemStrdup(bas->user);
res->port = bas->port; res->port = bas->port;
@ -2163,7 +2165,6 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
xmlChar *val = NULL; xmlChar *val = NULL;
int ret; int ret;
int ix; int ix;
int pos = 0;
int nbslash = 0; int nbslash = 0;
int len; int len;
xmlURIPtr ref = NULL; xmlURIPtr ref = NULL;
@ -2254,19 +2255,22 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
uptr = NULL; uptr = NULL;
len = 1; /* this is for a string terminator only */ len = 1; /* this is for a string terminator only */
} else { } else {
/* xmlChar *rptr = (xmlChar *) ref->path;
* Next we compare the two strings and find where they first differ int pos = 0;
*/
if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/')) /*
pos += 2; * Next we compare the two strings and find where they first differ
*/
if ((*rptr == '.') && (rptr[1] == '/'))
rptr += 2;
if ((*bptr == '.') && (bptr[1] == '/')) if ((*bptr == '.') && (bptr[1] == '/'))
bptr += 2; bptr += 2;
else if ((*bptr == '/') && (ref->path[pos] != '/')) else if ((*bptr == '/') && (*rptr != '/'))
bptr++; bptr++;
while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0)) while ((bptr[pos] == rptr[pos]) && (bptr[pos] != 0))
pos++; pos++;
if (bptr[pos] == ref->path[pos]) { if (bptr[pos] == rptr[pos]) {
val = xmlStrdup(BAD_CAST ""); val = xmlStrdup(BAD_CAST "");
goto done; /* (I can't imagine why anyone would do this) */ goto done; /* (I can't imagine why anyone would do this) */
} }
@ -2276,25 +2280,25 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
* beginning of the "unique" suffix of URI * beginning of the "unique" suffix of URI
*/ */
ix = pos; ix = pos;
if ((ref->path[ix] == '/') && (ix > 0)) if ((rptr[ix] == '/') && (ix > 0))
ix--; ix--;
else if ((ref->path[ix] == 0) && (ix > 1) && (ref->path[ix - 1] == '/')) else if ((rptr[ix] == 0) && (ix > 1) && (rptr[ix - 1] == '/'))
ix -= 2; ix -= 2;
for (; ix > 0; ix--) { for (; ix > 0; ix--) {
if (ref->path[ix] == '/') if (rptr[ix] == '/')
break; break;
} }
if (ix == 0) { if (ix == 0) {
uptr = (xmlChar *)ref->path; uptr = (xmlChar *)rptr;
} else { } else {
ix++; ix++;
uptr = (xmlChar *)&ref->path[ix]; uptr = (xmlChar *)&rptr[ix];
} }
/* /*
* In base, count the number of '/' from the differing point * In base, count the number of '/' from the differing point
*/ */
if (bptr[pos] != ref->path[pos]) {/* check for trivial URI == base */ if (bptr[pos] != rptr[pos]) {/* check for trivial URI == base */
for (; bptr[ix] != 0; ix++) { for (; bptr[ix] != 0; ix++) {
if (bptr[ix] == '/') if (bptr[ix] == '/')
nbslash++; nbslash++;
@ -2390,8 +2394,7 @@ xmlCanonicPath(const xmlChar *path)
*/ */
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
int len = 0; int len = 0;
int i = 0; char *p = NULL;
xmlChar *p = NULL;
#endif #endif
xmlURIPtr uri; xmlURIPtr uri;
xmlChar *ret; xmlChar *ret;
@ -2455,6 +2458,7 @@ xmlCanonicPath(const xmlChar *path)
xmlFreeURI(uri); xmlFreeURI(uri);
return escURI; return escURI;
} }
xmlFree(escURI);
} }
} }
@ -2472,7 +2476,7 @@ path_processing:
len = xmlStrlen(path); len = xmlStrlen(path);
if ((len > 2) && IS_WINDOWS_PATH(path)) { if ((len > 2) && IS_WINDOWS_PATH(path)) {
/* make the scheme 'file' */ /* make the scheme 'file' */
uri->scheme = xmlStrdup(BAD_CAST "file"); uri->scheme = (char *) xmlStrdup(BAD_CAST "file");
/* allocate space for leading '/' + path + string terminator */ /* allocate space for leading '/' + path + string terminator */
uri->path = xmlMallocAtomic(len + 2); uri->path = xmlMallocAtomic(len + 2);
if (uri->path == NULL) { if (uri->path == NULL) {
@ -2482,9 +2486,9 @@ path_processing:
/* Put in leading '/' plus path */ /* Put in leading '/' plus path */
uri->path[0] = '/'; uri->path[0] = '/';
p = uri->path + 1; p = uri->path + 1;
strncpy(p, path, len + 1); strncpy(p, (char *) path, len + 1);
} else { } else {
uri->path = xmlStrdup(path); uri->path = (char *) xmlStrdup(path);
if (uri->path == NULL) { if (uri->path == NULL) {
xmlFreeURI(uri); xmlFreeURI(uri);
return(NULL); return(NULL);

View file

@ -163,7 +163,7 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt,
__xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
XML_ERR_ERROR, NULL, 0, XML_ERR_ERROR, NULL, 0,
(const char *) str1, (const char *) str1,
(const char *) str1, (const char *) str2,
(const char *) str3, 0, 0, msg, str1, str2, str3); (const char *) str3, 0, 0, msg, str1, str2, str3);
} }
#endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */ #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
@ -247,7 +247,7 @@ xmlErrValidWarning(xmlValidCtxtPtr ctxt,
__xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error, __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
XML_ERR_WARNING, NULL, 0, XML_ERR_WARNING, NULL, 0,
(const char *) str1, (const char *) str1,
(const char *) str1, (const char *) str2,
(const char *) str3, 0, 0, msg, str1, str2, str3); (const char *) str3, 0, 0, msg, str1, str2, str3);
} }
@ -1172,29 +1172,33 @@ xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob)
xmlBufferWriteCHAR(buf, content->name); xmlBufferWriteCHAR(buf, content->name);
break; break;
case XML_ELEMENT_CONTENT_SEQ: case XML_ELEMENT_CONTENT_SEQ:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || if ((content->c1 != NULL) &&
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)) ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)))
xmlDumpElementContent(buf, content->c1, 1); xmlDumpElementContent(buf, content->c1, 1);
else else
xmlDumpElementContent(buf, content->c1, 0); xmlDumpElementContent(buf, content->c1, 0);
xmlBufferWriteChar(buf, " , "); xmlBufferWriteChar(buf, " , ");
if ((content->c2->type == XML_ELEMENT_CONTENT_OR) || if ((content->c2 != NULL) &&
((content->c2->type == XML_ELEMENT_CONTENT_SEQ) && ((content->c2->type == XML_ELEMENT_CONTENT_OR) ||
(content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))) ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) &&
(content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))))
xmlDumpElementContent(buf, content->c2, 1); xmlDumpElementContent(buf, content->c2, 1);
else else
xmlDumpElementContent(buf, content->c2, 0); xmlDumpElementContent(buf, content->c2, 0);
break; break;
case XML_ELEMENT_CONTENT_OR: case XML_ELEMENT_CONTENT_OR:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || if ((content->c1 != NULL) &&
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)) ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)))
xmlDumpElementContent(buf, content->c1, 1); xmlDumpElementContent(buf, content->c1, 1);
else else
xmlDumpElementContent(buf, content->c1, 0); xmlDumpElementContent(buf, content->c1, 0);
xmlBufferWriteChar(buf, " | "); xmlBufferWriteChar(buf, " | ");
if ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) || if ((content->c2 != NULL) &&
((content->c2->type == XML_ELEMENT_CONTENT_OR) && ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) ||
(content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))) ((content->c2->type == XML_ELEMENT_CONTENT_OR) &&
(content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))))
xmlDumpElementContent(buf, content->c2, 1); xmlDumpElementContent(buf, content->c2, 1);
else else
xmlDumpElementContent(buf, content->c2, 0); xmlDumpElementContent(buf, content->c2, 0);
@ -1262,22 +1266,23 @@ xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int
case XML_ELEMENT_CONTENT_PCDATA: case XML_ELEMENT_CONTENT_PCDATA:
strcat(buf, "#PCDATA"); strcat(buf, "#PCDATA");
break; break;
case XML_ELEMENT_CONTENT_ELEMENT: case XML_ELEMENT_CONTENT_ELEMENT: {
if (content->prefix != NULL) { int qnameLen = xmlStrlen(content->name);
if (size - len < xmlStrlen(content->prefix) + 10) {
strcat(buf, " ..."); if (content->prefix != NULL)
return; qnameLen += xmlStrlen(content->prefix) + 1;
} if (size - len < qnameLen + 10) {
strcat(buf, (char *) content->prefix);
strcat(buf, ":");
}
if (size - len < xmlStrlen(content->name) + 10) {
strcat(buf, " ..."); strcat(buf, " ...");
return; return;
} }
if (content->prefix != NULL) {
strcat(buf, (char *) content->prefix);
strcat(buf, ":");
}
if (content->name != NULL) if (content->name != NULL)
strcat(buf, (char *) content->name); strcat(buf, (char *) content->name);
break; break;
}
case XML_ELEMENT_CONTENT_SEQ: case XML_ELEMENT_CONTENT_SEQ:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)) (content->c1->type == XML_ELEMENT_CONTENT_SEQ))
@ -1319,6 +1324,7 @@ xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int
xmlSnprintfElementContent(buf, size, content->c2, 0); xmlSnprintfElementContent(buf, size, content->c2, 0);
break; break;
} }
if (size - strlen(buf) <= 2) return;
if (englob) if (englob)
strcat(buf, ")"); strcat(buf, ")");
switch (content->ocur) { switch (content->ocur) {
@ -4621,6 +4627,12 @@ xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) {
} }
} }
/*
* Casting ns to xmlAttrPtr is wrong. We'd need separate functions
* xmlAddID and xmlAddRef for namespace declarations, but it makes
* no practical sense to use ID types anyway.
*/
#if 0
/* Validity Constraint: ID uniqueness */ /* Validity Constraint: ID uniqueness */
if (attrDecl->atype == XML_ATTRIBUTE_ID) { if (attrDecl->atype == XML_ATTRIBUTE_ID) {
if (xmlAddID(ctxt, doc, value, (xmlAttrPtr) ns) == NULL) if (xmlAddID(ctxt, doc, value, (xmlAttrPtr) ns) == NULL)
@ -4632,6 +4644,7 @@ xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) {
if (xmlAddRef(ctxt, doc, value, (xmlAttrPtr) ns) == NULL) if (xmlAddRef(ctxt, doc, value, (xmlAttrPtr) ns) == NULL)
ret = 0; ret = 0;
} }
#endif
/* Validity Constraint: Notation Attributes */ /* Validity Constraint: Notation Attributes */
if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) { if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) {
@ -5177,6 +5190,7 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) {
case XML_TEXT_NODE: case XML_TEXT_NODE:
if (xmlIsBlankNode(cur)) if (xmlIsBlankNode(cur))
break; break;
/* Falls through. */
case XML_CDATA_SECTION_NODE: case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE: case XML_ENTITY_REF_NODE:
strcat(buf, "CDATA"); strcat(buf, "CDATA");
@ -5725,7 +5739,7 @@ xmlValidatePushElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
xmlElementPtr elemDecl; xmlElementPtr elemDecl;
/* /*
* Check the new element agaisnt the content model of the new elem. * Check the new element against the content model of the new elem.
*/ */
if (state->elemDecl != NULL) { if (state->elemDecl != NULL) {
elemDecl = state->elemDecl; elemDecl = state->elemDecl;
@ -5817,7 +5831,7 @@ xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) {
xmlElementPtr elemDecl; xmlElementPtr elemDecl;
/* /*
* Check the new element agaisnt the content model of the new elem. * Check the new element against the content model of the new elem.
*/ */
if (state->elemDecl != NULL) { if (state->elemDecl != NULL) {
elemDecl = state->elemDecl; elemDecl = state->elemDecl;
@ -5891,7 +5905,7 @@ xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED,
xmlElementPtr elemDecl; xmlElementPtr elemDecl;
/* /*
* Check the new element agaisnt the content model of the new elem. * Check the new element against the content model of the new elem.
*/ */
if (state->elemDecl != NULL) { if (state->elemDecl != NULL) {
elemDecl = state->elemDecl; elemDecl = state->elemDecl;

View file

@ -12,6 +12,7 @@
#include "libxml.h" #include "libxml.h"
#include <string.h> #include <string.h>
#include <stddef.h>
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
@ -39,7 +40,8 @@
#include <lzma.h> #include <lzma.h>
#endif #endif
#if defined(WIN32) || defined(_WIN32) #if defined(_WIN32) && !defined(__CYGWIN__)
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h> //#include <windows.h>
#include <winnls.h> #include <winnls.h>
#endif #endif
@ -48,38 +50,14 @@
#include <winnls.h> /* for CP_UTF8 */ #include <winnls.h> /* for CP_UTF8 */
#endif #endif
/* Figure a portable way to know if a file is a directory. */ #ifndef S_ISDIR
#ifndef HAVE_STAT # ifdef _S_ISDIR
# ifdef HAVE__STAT # define S_ISDIR(x) _S_ISDIR(x)
/* MS C library seems to define stat and _stat. The definition # elif defined(S_IFDIR)
is identical. Still, mapping them to each other causes a warning. */ # ifdef S_IFMT
# ifndef _MSC_VER # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# define stat(x,y) _stat(x,y) # elif defined(_S_IFMT)
# endif # define S_ISDIR(m) (((m) & _S_IFMT) == S_IFDIR)
# define HAVE_STAT
# endif
#else
# ifdef HAVE__STAT
# if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
# define stat _stat
# endif
# endif
#endif
#ifdef HAVE_STAT
# ifndef S_ISDIR
# ifdef _S_ISDIR
# define S_ISDIR(x) _S_ISDIR(x)
# else
# ifdef S_IFDIR
# ifndef S_IFMT
# ifdef _S_IFMT
# define S_IFMT _S_IFMT
# endif
# endif
# ifdef S_IFMT
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# endif
# endif
# endif # endif
# endif # endif
#endif #endif
@ -657,99 +635,19 @@ xmlWrapGzOpenUtf8(const char *path, const char *mode)
* *
*/ */
static int static int
xmlWrapStatUtf8(const char *path,struct stat *info) xmlWrapStatUtf8(const char *path, struct _stat *info) {
{
#ifdef HAVE_STAT
int retval = -1; int retval = -1;
wchar_t *wPath; wchar_t *wPath;
wPath = __xmlIOWin32UTF8ToWChar(path); wPath = __xmlIOWin32UTF8ToWChar(path);
if (wPath) if (wPath) {
{ retval = _wstat(wPath, info);
retval = _wstat(wPath,info);
xmlFree(wPath); xmlFree(wPath);
} }
/* maybe path in native encoding */ /* maybe path in native encoding */
if(retval < 0) if(retval < 0)
retval = stat(path,info); retval = _stat(path, info);
return retval; return retval;
#else
return -1;
#endif
}
/**
* xmlWrapOpenNative:
* @path: the path
* @mode: type of access (0 - read, 1 - write)
*
* function opens the file specified by @path
*
*/
static FILE*
xmlWrapOpenNative(const char *path,int mode)
{
return fopen(path,mode ? "wb" : "rb");
}
/**
* xmlWrapStatNative:
* @path: the path
* @info: structure that stores results
*
* function obtains information about the file or directory
*
*/
static int
xmlWrapStatNative(const char *path,struct stat *info)
{
#ifdef HAVE_STAT
return stat(path,info);
#else
return -1;
#endif
}
typedef int (* xmlWrapStatFunc) (const char *f, struct stat *s);
static xmlWrapStatFunc xmlWrapStat = xmlWrapStatNative;
typedef FILE* (* xmlWrapOpenFunc)(const char *f,int mode);
static xmlWrapOpenFunc xmlWrapOpen = xmlWrapOpenNative;
#ifdef HAVE_ZLIB_H
typedef gzFile (* xmlWrapGzOpenFunc) (const char *f, const char *mode);
static xmlWrapGzOpenFunc xmlWrapGzOpen = gzopen;
#endif
/**
* xmlInitPlatformSpecificIo:
*
* Initialize platform specific features.
*/
static void
xmlInitPlatformSpecificIo(void)
{
static int xmlPlatformIoInitialized = 0;
OSVERSIONINFO osvi;
if(xmlPlatformIoInitialized)
return;
osvi.dwOSVersionInfoSize = sizeof(osvi);
if(GetVersionEx(&osvi) && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)) {
xmlWrapStat = xmlWrapStatUtf8;
xmlWrapOpen = xmlWrapOpenUtf8;
#ifdef HAVE_ZLIB_H
xmlWrapGzOpen = xmlWrapGzOpenUtf8;
#endif
} else {
xmlWrapStat = xmlWrapStatNative;
xmlWrapOpen = xmlWrapOpenNative;
#ifdef HAVE_ZLIB_H
xmlWrapGzOpen = gzopen;
#endif
}
xmlPlatformIoInitialized = 1;
return;
} }
#endif #endif
@ -772,7 +670,11 @@ int
xmlCheckFilename (const char *path) xmlCheckFilename (const char *path)
{ {
#ifdef HAVE_STAT #ifdef HAVE_STAT
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
struct _stat stat_buffer;
#else
struct stat stat_buffer; struct stat stat_buffer;
#endif
#endif #endif
if (path == NULL) if (path == NULL)
return(0); return(0);
@ -787,7 +689,7 @@ xmlCheckFilename (const char *path)
(path[3] == '\\') ) (path[3] == '\\') )
return 1; return 1;
if (xmlWrapStat(path, &stat_buffer) == -1) if (xmlWrapStatUtf8(path, &stat_buffer) == -1)
return 0; return 0;
#else #else
if (stat(path, &stat_buffer) == -1) if (stat(path, &stat_buffer) == -1)
@ -827,7 +729,7 @@ static int
xmlFdRead (void * context, char * buffer, int len) { xmlFdRead (void * context, char * buffer, int len) {
int ret; int ret;
ret = read((int) (long) context, &buffer[0], len); ret = read((int) (ptrdiff_t) context, &buffer[0], len);
if (ret < 0) xmlIOErr(0, "read()"); if (ret < 0) xmlIOErr(0, "read()");
return(ret); return(ret);
} }
@ -848,7 +750,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
int ret = 0; int ret = 0;
if (len > 0) { if (len > 0) {
ret = write((int) (long) context, &buffer[0], len); ret = write((int) (ptrdiff_t) context, &buffer[0], len);
if (ret < 0) xmlIOErr(0, "write()"); if (ret < 0) xmlIOErr(0, "write()");
} }
return(ret); return(ret);
@ -866,7 +768,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
static int static int
xmlFdClose (void * context) { xmlFdClose (void * context) {
int ret; int ret;
ret = close((int) (long) context); ret = close((int) (ptrdiff_t) context);
if (ret < 0) xmlIOErr(0, "close()"); if (ret < 0) xmlIOErr(0, "close()");
return(ret); return(ret);
} }
@ -927,11 +829,14 @@ xmlFileOpen_real (const char *filename) {
#endif #endif
} }
/* Do not check DDNAME on zOS ! */
#if !defined(__MVS__)
if (!xmlCheckFilename(path)) if (!xmlCheckFilename(path))
return(NULL); return(NULL);
#endif
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapOpen(path, 0); fd = xmlWrapOpenUtf8(path, 0);
#else #else
fd = fopen(path, "r"); fd = fopen(path, "r");
#endif /* WIN32 */ #endif /* WIN32 */
@ -1004,12 +909,14 @@ xmlFileOpenW (const char *filename) {
return(NULL); return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapOpen(path, 1); fd = xmlWrapOpenUtf8(path, 1);
#elif(__MVS__)
fd = fopen(path, "w");
#else #else
fd = fopen(path, "wb"); fd = fopen(path, "wb");
#endif /* WIN32 */ #endif /* WIN32 */
if (fd == NULL) xmlIOErr(0, path); if (fd == NULL) xmlIOErr(0, path);
return((void *) fd); return((void *) fd);
} }
#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* LIBXML_OUTPUT_ENABLED */
@ -1194,7 +1101,7 @@ xmlGzfileOpen_real (const char *filename) {
return(NULL); return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, "rb"); fd = xmlWrapGzOpenUtf8(path, "rb");
#else #else
fd = gzopen(path, "rb"); fd = gzopen(path, "rb");
#endif #endif
@ -1271,7 +1178,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
return(NULL); return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, mode); fd = xmlWrapGzOpenUtf8(path, mode);
#else #else
fd = gzopen(path, mode); fd = gzopen(path, mode);
#endif #endif
@ -1287,7 +1194,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
* *
* Read @len bytes to @buffer from the compressed I/O channel. * Read @len bytes to @buffer from the compressed I/O channel.
* *
* Returns the number of bytes written * Returns the number of bytes read.
*/ */
static int static int
xmlGzfileRead (void * context, char * buffer, int len) { xmlGzfileRead (void * context, char * buffer, int len) {
@ -1675,7 +1582,7 @@ xmlZMemBuffExtend( xmlZMemBuffPtr buff, size_t ext_amt ) {
xmlStrPrintf(msg, 500, xmlStrPrintf(msg, 500,
"xmlZMemBuffExtend: %s %lu bytes.\n", "xmlZMemBuffExtend: %s %lu bytes.\n",
"Allocation failure extending output buffer to", "Allocation failure extending output buffer to",
new_size ); (unsigned long) new_size );
xmlIOErr(XML_IO_WRITE, (const char *) msg); xmlIOErr(XML_IO_WRITE, (const char *) msg);
} }
@ -1877,7 +1784,7 @@ xmlIOHTTPOpen (const char *filename) {
*/ */
void * void *
xmlIOHTTPOpenW(const char *post_uri, int compression) xmlIOHTTPOpenW(const char *post_uri, int compression ATTRIBUTE_UNUSED)
{ {
xmlIOHTTPWriteCtxtPtr ctxt = NULL; xmlIOHTTPWriteCtxtPtr ctxt = NULL;
@ -2319,10 +2226,6 @@ xmlRegisterDefaultInputCallbacks(void) {
if (xmlInputCallbackInitialized) if (xmlInputCallbackInitialized)
return; return;
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
xmlInitPlatformSpecificIo();
#endif
xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen, xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen,
xmlFileRead, xmlFileClose); xmlFileRead, xmlFileClose);
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
@ -2357,10 +2260,6 @@ xmlRegisterDefaultOutputCallbacks (void) {
if (xmlOutputCallbackInitialized) if (xmlOutputCallbackInitialized)
return; return;
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
xmlInitPlatformSpecificIo();
#endif
xmlRegisterOutputCallbacks(xmlFileMatch, xmlFileOpenW, xmlRegisterOutputCallbacks(xmlFileMatch, xmlFileOpenW,
xmlFileWrite, xmlFileClose); xmlFileWrite, xmlFileClose);
@ -3004,7 +2903,7 @@ xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) {
ret = xmlAllocParserInputBuffer(enc); ret = xmlAllocParserInputBuffer(enc);
if (ret != NULL) { if (ret != NULL) {
ret->context = (void *) (long) fd; ret->context = (void *) (ptrdiff_t) fd;
ret->readcallback = xmlFdRead; ret->readcallback = xmlFdRead;
ret->closecallback = xmlFdClose; ret->closecallback = xmlFdClose;
} }
@ -3028,7 +2927,7 @@ xmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc) {
xmlParserInputBufferPtr ret; xmlParserInputBufferPtr ret;
int errcode; int errcode;
if (size <= 0) return(NULL); if (size < 0) return(NULL);
if (mem == NULL) return(NULL); if (mem == NULL) return(NULL);
ret = xmlAllocParserInputBuffer(enc); ret = xmlAllocParserInputBuffer(enc);
@ -3064,7 +2963,7 @@ xmlParserInputBufferCreateStatic(const char *mem, int size,
xmlCharEncoding enc) { xmlCharEncoding enc) {
xmlParserInputBufferPtr ret; xmlParserInputBufferPtr ret;
if (size <= 0) return(NULL); if (size < 0) return(NULL);
if (mem == NULL) return(NULL); if (mem == NULL) return(NULL);
ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer)); ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer));
@ -3110,7 +3009,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) {
ret = xmlAllocOutputBufferInternal(encoder); ret = xmlAllocOutputBufferInternal(encoder);
if (ret != NULL) { if (ret != NULL) {
ret->context = (void *) (long) fd; ret->context = (void *) (ptrdiff_t) fd;
ret->writecallback = xmlFdWrite; ret->writecallback = xmlFdWrite;
ret->closecallback = NULL; ret->closecallback = NULL;
} }
@ -3824,7 +3723,7 @@ xmlParserGetDirectory(const char *filename) {
if (filename == NULL) return(NULL); if (filename == NULL) return(NULL);
#if defined(WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
# define IS_XMLPGD_SEP(ch) ((ch=='/')||(ch=='\\')) # define IS_XMLPGD_SEP(ch) ((ch=='/')||(ch=='\\'))
#else #else
# define IS_XMLPGD_SEP(ch) (ch=='/') # define IS_XMLPGD_SEP(ch) (ch=='/')

View file

@ -312,7 +312,8 @@ static void usage(const char *name) {
/* split into 2 printf's to avoid overly long string (gcc warning) */ /* split into 2 printf's to avoid overly long string (gcc warning) */
printf("\ printf("\
Usage : %s [options] catalogfile entities...\n\ Usage : %s [options] catalogfile entities...\n\
\tParse the catalog file and query it for the entities\n\ \tParse the catalog file (void specification possibly expressed as \"\"\n\
\tappoints the default system one) and query it for the entities\n\
\t--sgml : handle SGML Super catalogs for --add and --del\n\ \t--sgml : handle SGML Super catalogs for --add and --del\n\
\t--shell : run a shell allowing interactive queries\n\ \t--shell : run a shell allowing interactive queries\n\
\t--create : create a new catalog\n\ \t--create : create a new catalog\n\
@ -408,11 +409,18 @@ int main(int argc, char **argv) {
continue; continue;
} else if (argv[i][0] == '-') } else if (argv[i][0] == '-')
continue; continue;
filename = argv[i];
if (filename == NULL && argv[i][0] == '\0') {
/* Interpret empty-string catalog specification as
a shortcut for a default system catalog. */
xmlInitializeCatalog();
} else {
filename = argv[i];
ret = xmlLoadCatalog(argv[i]); ret = xmlLoadCatalog(argv[i]);
if ((ret < 0) && (create)) { if ((ret < 0) && (create)) {
xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL); xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL);
} }
}
break; break;
} }

View file

@ -12,14 +12,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
#if defined (_WIN32) && !defined(__CYGWIN__)
#if defined (_MSC_VER) || defined(__BORLANDC__)
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#define gettimeofday(p1,p2)
#endif /* _MSC_VER */
#endif /* _WIN32 */
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -27,14 +19,6 @@
#include <time.h> #include <time.h>
#endif #endif
#ifdef __MINGW32__
#define _WINSOCKAPI_
#include <wsockcompat.h>
#include <winsock2.h>
#undef XML_SOCKLEN_T
#define XML_SOCKLEN_T unsigned int
#endif
#ifdef HAVE_SYS_TIMEB_H #ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h> #include <sys/timeb.h>
#endif #endif
@ -2991,124 +2975,124 @@ static void showVersion(const char *name) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
static void usage(const char *name) { static void usage(FILE *f, const char *name) {
printf("Usage : %s [options] XMLfiles ...\n", name); fprintf(f, "Usage : %s [options] XMLfiles ...\n", name);
#ifdef LIBXML_OUTPUT_ENABLED #ifdef LIBXML_OUTPUT_ENABLED
printf("\tParse the XML files and output the result of the parsing\n"); fprintf(f, "\tParse the XML files and output the result of the parsing\n");
#else #else
printf("\tParse the XML files\n"); fprintf(f, "\tParse the XML files\n");
#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* LIBXML_OUTPUT_ENABLED */
printf("\t--version : display the version of the XML library used\n"); fprintf(f, "\t--version : display the version of the XML library used\n");
#ifdef LIBXML_DEBUG_ENABLED #ifdef LIBXML_DEBUG_ENABLED
printf("\t--debug : dump a debug tree of the in-memory document\n"); fprintf(f, "\t--debug : dump a debug tree of the in-memory document\n");
printf("\t--shell : run a navigating shell\n"); fprintf(f, "\t--shell : run a navigating shell\n");
printf("\t--debugent : debug the entities defined in the document\n"); fprintf(f, "\t--debugent : debug the entities defined in the document\n");
#else #else
#ifdef LIBXML_READER_ENABLED #ifdef LIBXML_READER_ENABLED
printf("\t--debug : dump the nodes content when using --stream\n"); fprintf(f, "\t--debug : dump the nodes content when using --stream\n");
#endif /* LIBXML_READER_ENABLED */ #endif /* LIBXML_READER_ENABLED */
#endif #endif
#ifdef LIBXML_TREE_ENABLED #ifdef LIBXML_TREE_ENABLED
printf("\t--copy : used to test the internal copy implementation\n"); fprintf(f, "\t--copy : used to test the internal copy implementation\n");
#endif /* LIBXML_TREE_ENABLED */ #endif /* LIBXML_TREE_ENABLED */
printf("\t--recover : output what was parsable on broken XML documents\n"); fprintf(f, "\t--recover : output what was parsable on broken XML documents\n");
printf("\t--huge : remove any internal arbitrary parser limits\n"); fprintf(f, "\t--huge : remove any internal arbitrary parser limits\n");
printf("\t--noent : substitute entity references by their value\n"); fprintf(f, "\t--noent : substitute entity references by their value\n");
printf("\t--noenc : ignore any encoding specified inside the document\n"); fprintf(f, "\t--noenc : ignore any encoding specified inside the document\n");
printf("\t--noout : don't output the result tree\n"); fprintf(f, "\t--noout : don't output the result tree\n");
printf("\t--path 'paths': provide a set of paths for resources\n"); fprintf(f, "\t--path 'paths': provide a set of paths for resources\n");
printf("\t--load-trace : print trace of all external entities loaded\n"); fprintf(f, "\t--load-trace : print trace of all external entities loaded\n");
printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); fprintf(f, "\t--nonet : refuse to fetch DTDs or entities over network\n");
printf("\t--nocompact : do not generate compact text nodes\n"); fprintf(f, "\t--nocompact : do not generate compact text nodes\n");
printf("\t--htmlout : output results as HTML\n"); fprintf(f, "\t--htmlout : output results as HTML\n");
printf("\t--nowrap : do not put HTML doc wrapper\n"); fprintf(f, "\t--nowrap : do not put HTML doc wrapper\n");
#ifdef LIBXML_VALID_ENABLED #ifdef LIBXML_VALID_ENABLED
printf("\t--valid : validate the document in addition to std well-formed check\n"); fprintf(f, "\t--valid : validate the document in addition to std well-formed check\n");
printf("\t--postvalid : do a posteriori validation, i.e after parsing\n"); fprintf(f, "\t--postvalid : do a posteriori validation, i.e after parsing\n");
printf("\t--dtdvalid URL : do a posteriori validation against a given DTD\n"); fprintf(f, "\t--dtdvalid URL : do a posteriori validation against a given DTD\n");
printf("\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n"); fprintf(f, "\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n");
#endif /* LIBXML_VALID_ENABLED */ #endif /* LIBXML_VALID_ENABLED */
printf("\t--timing : print some timings\n"); fprintf(f, "\t--timing : print some timings\n");
printf("\t--output file or -o file: save to a given file\n"); fprintf(f, "\t--output file or -o file: save to a given file\n");
printf("\t--repeat : repeat 100 times, for timing or profiling\n"); fprintf(f, "\t--repeat : repeat 100 times, for timing or profiling\n");
printf("\t--insert : ad-hoc test for valid insertions\n"); fprintf(f, "\t--insert : ad-hoc test for valid insertions\n");
#ifdef LIBXML_OUTPUT_ENABLED #ifdef LIBXML_OUTPUT_ENABLED
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
printf("\t--compress : turn on gzip compression of output\n"); fprintf(f, "\t--compress : turn on gzip compression of output\n");
#endif #endif
#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_HTML_ENABLED #ifdef LIBXML_HTML_ENABLED
printf("\t--html : use the HTML parser\n"); fprintf(f, "\t--html : use the HTML parser\n");
printf("\t--xmlout : force to use the XML serializer when using --html\n"); fprintf(f, "\t--xmlout : force to use the XML serializer when using --html\n");
printf("\t--nodefdtd : do not default HTML doctype\n"); fprintf(f, "\t--nodefdtd : do not default HTML doctype\n");
#endif #endif
#ifdef LIBXML_PUSH_ENABLED #ifdef LIBXML_PUSH_ENABLED
printf("\t--push : use the push mode of the parser\n"); fprintf(f, "\t--push : use the push mode of the parser\n");
printf("\t--pushsmall : use the push mode of the parser using tiny increments\n"); fprintf(f, "\t--pushsmall : use the push mode of the parser using tiny increments\n");
#endif /* LIBXML_PUSH_ENABLED */ #endif /* LIBXML_PUSH_ENABLED */
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
printf("\t--memory : parse from memory\n"); fprintf(f, "\t--memory : parse from memory\n");
#endif #endif
printf("\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n"); fprintf(f, "\t--maxmem nbbytes : limits memory allocation to nbbytes bytes\n");
printf("\t--nowarning : do not emit warnings from parser/validator\n"); fprintf(f, "\t--nowarning : do not emit warnings from parser/validator\n");
printf("\t--noblanks : drop (ignorable?) blanks spaces\n"); fprintf(f, "\t--noblanks : drop (ignorable?) blanks spaces\n");
printf("\t--nocdata : replace cdata section with text nodes\n"); fprintf(f, "\t--nocdata : replace cdata section with text nodes\n");
#ifdef LIBXML_OUTPUT_ENABLED #ifdef LIBXML_OUTPUT_ENABLED
printf("\t--format : reformat/reindent the output\n"); fprintf(f, "\t--format : reformat/reindent the output\n");
printf("\t--encode encoding : output in the given encoding\n"); fprintf(f, "\t--encode encoding : output in the given encoding\n");
printf("\t--dropdtd : remove the DOCTYPE of the input docs\n"); fprintf(f, "\t--dropdtd : remove the DOCTYPE of the input docs\n");
printf("\t--pretty STYLE : pretty-print in a particular style\n"); fprintf(f, "\t--pretty STYLE : pretty-print in a particular style\n");
printf("\t 0 Do not pretty print\n"); fprintf(f, "\t 0 Do not pretty print\n");
printf("\t 1 Format the XML content, as --format\n"); fprintf(f, "\t 1 Format the XML content, as --format\n");
printf("\t 2 Add whitespace inside tags, preserving content\n"); fprintf(f, "\t 2 Add whitespace inside tags, preserving content\n");
#endif /* LIBXML_OUTPUT_ENABLED */ #endif /* LIBXML_OUTPUT_ENABLED */
printf("\t--c14n : save in W3C canonical format v1.0 (with comments)\n"); fprintf(f, "\t--c14n : save in W3C canonical format v1.0 (with comments)\n");
printf("\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n"); fprintf(f, "\t--c14n11 : save in W3C canonical format v1.1 (with comments)\n");
printf("\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n"); fprintf(f, "\t--exc-c14n : save in W3C exclusive canonical format (with comments)\n");
#ifdef LIBXML_C14N_ENABLED #ifdef LIBXML_C14N_ENABLED
#endif /* LIBXML_C14N_ENABLED */ #endif /* LIBXML_C14N_ENABLED */
printf("\t--nsclean : remove redundant namespace declarations\n"); fprintf(f, "\t--nsclean : remove redundant namespace declarations\n");
printf("\t--testIO : test user I/O support\n"); fprintf(f, "\t--testIO : test user I/O support\n");
#ifdef LIBXML_CATALOG_ENABLED #ifdef LIBXML_CATALOG_ENABLED
printf("\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n"); fprintf(f, "\t--catalogs : use SGML catalogs from $SGML_CATALOG_FILES\n");
printf("\t otherwise XML Catalogs starting from \n"); fprintf(f, "\t otherwise XML Catalogs starting from \n");
printf("\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG); fprintf(f, "\t %s are activated by default\n", XML_XML_DEFAULT_CATALOG);
printf("\t--nocatalogs: deactivate all catalogs\n"); fprintf(f, "\t--nocatalogs: deactivate all catalogs\n");
#endif #endif
printf("\t--auto : generate a small doc on the fly\n"); fprintf(f, "\t--auto : generate a small doc on the fly\n");
#ifdef LIBXML_XINCLUDE_ENABLED #ifdef LIBXML_XINCLUDE_ENABLED
printf("\t--xinclude : do XInclude processing\n"); fprintf(f, "\t--xinclude : do XInclude processing\n");
printf("\t--noxincludenode : same but do not generate XInclude nodes\n"); fprintf(f, "\t--noxincludenode : same but do not generate XInclude nodes\n");
printf("\t--nofixup-base-uris : do not fixup xml:base uris\n"); fprintf(f, "\t--nofixup-base-uris : do not fixup xml:base uris\n");
#endif #endif
printf("\t--loaddtd : fetch external DTD\n"); fprintf(f, "\t--loaddtd : fetch external DTD\n");
printf("\t--dtdattr : loaddtd + populate the tree with inherited attributes \n"); fprintf(f, "\t--dtdattr : loaddtd + populate the tree with inherited attributes \n");
#ifdef LIBXML_READER_ENABLED #ifdef LIBXML_READER_ENABLED
printf("\t--stream : use the streaming interface to process very large files\n"); fprintf(f, "\t--stream : use the streaming interface to process very large files\n");
printf("\t--walker : create a reader and walk though the resulting doc\n"); fprintf(f, "\t--walker : create a reader and walk though the resulting doc\n");
#endif /* LIBXML_READER_ENABLED */ #endif /* LIBXML_READER_ENABLED */
#ifdef LIBXML_PATTERN_ENABLED #ifdef LIBXML_PATTERN_ENABLED
printf("\t--pattern pattern_value : test the pattern support\n"); fprintf(f, "\t--pattern pattern_value : test the pattern support\n");
#endif #endif
printf("\t--chkregister : verify the node registration code\n"); fprintf(f, "\t--chkregister : verify the node registration code\n");
#ifdef LIBXML_SCHEMAS_ENABLED #ifdef LIBXML_SCHEMAS_ENABLED
printf("\t--relaxng schema : do RelaxNG validation against the schema\n"); fprintf(f, "\t--relaxng schema : do RelaxNG validation against the schema\n");
printf("\t--schema schema : do validation against the WXS schema\n"); fprintf(f, "\t--schema schema : do validation against the WXS schema\n");
#endif #endif
#ifdef LIBXML_SCHEMATRON_ENABLED #ifdef LIBXML_SCHEMATRON_ENABLED
printf("\t--schematron schema : do validation against a schematron\n"); fprintf(f, "\t--schematron schema : do validation against a schematron\n");
#endif #endif
#ifdef LIBXML_SAX1_ENABLED #ifdef LIBXML_SAX1_ENABLED
printf("\t--sax1: use the old SAX1 interfaces for processing\n"); fprintf(f, "\t--sax1: use the old SAX1 interfaces for processing\n");
#endif #endif
printf("\t--sax: do not build a tree but work just at the SAX level\n"); fprintf(f, "\t--sax: do not build a tree but work just at the SAX level\n");
printf("\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n"); fprintf(f, "\t--oldxml10: use XML-1.0 parsing rules before the 5th edition\n");
#ifdef LIBXML_XPATH_ENABLED #ifdef LIBXML_XPATH_ENABLED
printf("\t--xpath expr: evaluate the XPath expression, imply --noout\n"); fprintf(f, "\t--xpath expr: evaluate the XPath expression, imply --noout\n");
#endif #endif
printf("\nLibxml project home page: http://xmlsoft.org/\n"); fprintf(f, "\nLibxml project home page: http://xmlsoft.org/\n");
printf("To report bugs or get some help check: http://xmlsoft.org/bugs.html\n"); fprintf(f, "To report bugs or get some help check: http://xmlsoft.org/bugs.html\n");
} }
static void registerNode(xmlNodePtr node) static void registerNode(xmlNodePtr node)
@ -3138,7 +3122,7 @@ main(int argc, char **argv) {
const char* indent; const char* indent;
if (argc <= 1) { if (argc <= 1) {
usage(argv[0]); usage(stderr, argv[0]);
return(1); return(1);
} }
LIBXML_TEST_VERSION LIBXML_TEST_VERSION
@ -3490,7 +3474,7 @@ main(int argc, char **argv) {
options |= XML_PARSE_OLD10; options |= XML_PARSE_OLD10;
} else { } else {
fprintf(stderr, "Unknown option %s\n", argv[i]); fprintf(stderr, "Unknown option %s\n", argv[i]);
usage(argv[0]); usage(stderr, argv[0]);
return(1); return(1);
} }
} }
@ -3784,7 +3768,7 @@ main(int argc, char **argv) {
xmlGenericError(xmlGenericErrorContext, "</body></html>\n"); xmlGenericError(xmlGenericErrorContext, "</body></html>\n");
} }
if ((files == 0) && (!generate) && (version == 0)) { if ((files == 0) && (!generate) && (version == 0)) {
usage(argv[0]); usage(stderr, argv[0]);
} }
#ifdef LIBXML_SCHEMATRON_ENABLED #ifdef LIBXML_SCHEMATRON_ENABLED
if (wxschematron != NULL) if (wxschematron != NULL)

View file

@ -111,7 +111,7 @@ typedef struct memnod {
#define MAX_SIZE_T ((size_t)-1) #define MAX_SIZE_T ((size_t)-1)
#define CLIENT_2_HDR(a) ((MEMHDR *) (((char *) (a)) - RESERVE_SIZE)) #define CLIENT_2_HDR(a) ((void *) (((char *) (a)) - RESERVE_SIZE))
#define HDR_2_CLIENT(a) ((void *) (((char *) (a)) + RESERVE_SIZE)) #define HDR_2_CLIENT(a) ((void *) (((char *) (a)) + RESERVE_SIZE))
@ -172,6 +172,13 @@ xmlMallocLoc(size_t size, const char * file, int line)
TEST_POINT TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
"xmlMallocLoc : Unsigned overflow\n");
xmlMemoryDump();
return(NULL);
}
p = (MEMHDR *) malloc(RESERVE_SIZE+size); p = (MEMHDR *) malloc(RESERVE_SIZE+size);
if (!p) { if (!p) {
@ -243,7 +250,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
if (size > (MAX_SIZE_T - RESERVE_SIZE)) { if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlMallocAtomicLoc : Unsigned overflow prevented\n"); "xmlMallocAtomicLoc : Unsigned overflow\n");
xmlMemoryDump(); xmlMemoryDump();
return(NULL); return(NULL);
} }
@ -352,6 +359,13 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
#endif #endif
xmlMutexUnlock(xmlMemMutex); xmlMutexUnlock(xmlMemMutex);
if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
"xmlReallocLoc : Unsigned overflow\n");
xmlMemoryDump();
return(NULL);
}
tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size); tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
if (!tmp) { if (!tmp) {
free(p); free(p);
@ -473,7 +487,7 @@ xmlMemFree(void *ptr)
error: error:
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"xmlMemFree(%lX) error\n", (unsigned long) ptr); "xmlMemFree(%p) error\n", ptr);
xmlMallocBreakpoint(); xmlMallocBreakpoint();
return; return;
} }
@ -499,6 +513,13 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
if (!xmlMemInitialized) xmlInitMemory(); if (!xmlMemInitialized) xmlInitMemory();
TEST_POINT TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext,
"xmlMemStrdupLoc : Unsigned overflow\n");
xmlMemoryDump();
return(NULL);
}
p = (MEMHDR *) malloc(RESERVE_SIZE+size); p = (MEMHDR *) malloc(RESERVE_SIZE+size);
if (!p) { if (!p) {
goto error; goto error;

View file

@ -8,6 +8,11 @@
* http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html * http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html
*/ */
/* In order RTLD_GLOBAL and RTLD_NOW to be defined on zOS */
#if defined(__MVS__)
#define _UNIX03_SOURCE
#endif
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
@ -296,9 +301,10 @@ xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
#endif /* HAVE_SHLLOAD */ #endif /* HAVE_SHLLOAD */
#endif /* ! HAVE_DLOPEN */ #endif /* ! HAVE_DLOPEN */
#ifdef _WIN32 #if defined(_WIN32) && !defined(__CYGWIN__)
//#include <windows.h> #define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* /*
* xmlModulePlatformOpen: * xmlModulePlatformOpen:

View file

@ -3982,7 +3982,7 @@ xmlTextReaderPreserve(xmlTextReaderPtr reader) {
* pattern. The caller must also use xmlTextReaderCurrentDoc() to * pattern. The caller must also use xmlTextReaderCurrentDoc() to
* keep an handle on the resulting document once parsing has finished * keep an handle on the resulting document once parsing has finished
* *
* Returns a positive number in case of success and -1 in case of error * Returns a non-negative number in case of success and -1 in case of error
*/ */
int int
xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern, xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern,

View file

@ -2810,18 +2810,21 @@ xmlRegCheckCharacterRange(xmlRegAtomType type, int codepoint, int neg,
break; break;
case XML_REGEXP_NOTSPACE: case XML_REGEXP_NOTSPACE:
neg = !neg; neg = !neg;
/* Falls through. */
case XML_REGEXP_ANYSPACE: case XML_REGEXP_ANYSPACE:
ret = ((codepoint == '\n') || (codepoint == '\r') || ret = ((codepoint == '\n') || (codepoint == '\r') ||
(codepoint == '\t') || (codepoint == ' ')); (codepoint == '\t') || (codepoint == ' '));
break; break;
case XML_REGEXP_NOTINITNAME: case XML_REGEXP_NOTINITNAME:
neg = !neg; neg = !neg;
/* Falls through. */
case XML_REGEXP_INITNAME: case XML_REGEXP_INITNAME:
ret = (IS_LETTER(codepoint) || ret = (IS_LETTER(codepoint) ||
(codepoint == '_') || (codepoint == ':')); (codepoint == '_') || (codepoint == ':'));
break; break;
case XML_REGEXP_NOTNAMECHAR: case XML_REGEXP_NOTNAMECHAR:
neg = !neg; neg = !neg;
/* Falls through. */
case XML_REGEXP_NAMECHAR: case XML_REGEXP_NAMECHAR:
ret = (IS_LETTER(codepoint) || IS_DIGIT(codepoint) || ret = (IS_LETTER(codepoint) || IS_DIGIT(codepoint) ||
(codepoint == '.') || (codepoint == '-') || (codepoint == '.') || (codepoint == '-') ||
@ -2830,11 +2833,13 @@ xmlRegCheckCharacterRange(xmlRegAtomType type, int codepoint, int neg,
break; break;
case XML_REGEXP_NOTDECIMAL: case XML_REGEXP_NOTDECIMAL:
neg = !neg; neg = !neg;
/* Falls through. */
case XML_REGEXP_DECIMAL: case XML_REGEXP_DECIMAL:
ret = xmlUCSIsCatNd(codepoint); ret = xmlUCSIsCatNd(codepoint);
break; break;
case XML_REGEXP_REALCHAR: case XML_REGEXP_REALCHAR:
neg = !neg; neg = !neg;
/* Falls through. */
case XML_REGEXP_NOTREALCHAR: case XML_REGEXP_NOTREALCHAR:
ret = xmlUCSIsCatP(codepoint); ret = xmlUCSIsCatP(codepoint);
if (ret == 0) if (ret == 0)
@ -4089,8 +4094,9 @@ rollback:
xmlFree(exec->errString); xmlFree(exec->errString);
exec->errString = xmlStrdup(value); exec->errString = xmlStrdup(value);
exec->errState = exec->state; exec->errState = exec->state;
memcpy(exec->errCounts, exec->counts, if (exec->comp->nbCounters)
exec->comp->nbCounters * sizeof(int)); memcpy(exec->errCounts, exec->counts,
exec->comp->nbCounters * sizeof(int));
} }
/* /*
@ -4880,7 +4886,8 @@ xmlFAParseCharClassEsc(xmlRegParserCtxtPtr ctxt) {
} }
NEXT; NEXT;
xmlFAParseCharProp(ctxt); xmlFAParseCharProp(ctxt);
ctxt->atom->neg = 1; if (ctxt->atom != NULL)
ctxt->atom->neg = 1;
if (CUR != '}') { if (CUR != '}') {
ERROR("Expecting '}'"); ERROR("Expecting '}'");
return; return;
@ -5051,7 +5058,7 @@ xmlFAParseCharRange(xmlRegParserCtxtPtr ctxt) {
return; return;
} }
len = 1; len = 1;
} else if ((cur != 0x5B) && (cur != 0x5D)) { } else if ((cur != '\0') && (cur != 0x5B) && (cur != 0x5D)) {
end = CUR_SCHAR(ctxt->cur, len); end = CUR_SCHAR(ctxt->cur, len);
} else { } else {
ERROR("Expecting the end of a char range"); ERROR("Expecting the end of a char range");

View file

@ -2109,8 +2109,6 @@ xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc,
xmlBufAdd(buf, base, cur - base); xmlBufAdd(buf, base, cur - base);
if (*cur < 0xC0) { if (*cur < 0xC0) {
xmlSaveErr(XML_SAVE_NOT_UTF8, (xmlNodePtr) attr, NULL); xmlSaveErr(XML_SAVE_NOT_UTF8, (xmlNodePtr) attr, NULL);
if (doc != NULL)
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
xmlSerializeHexCharRef(tmp, *cur); xmlSerializeHexCharRef(tmp, *cur);
xmlBufAdd(buf, (xmlChar *) tmp, -1); xmlBufAdd(buf, (xmlChar *) tmp, -1);
cur++; cur++;
@ -2140,9 +2138,6 @@ xmlBufAttrSerializeTxtContent(xmlBufPtr buf, xmlDocPtr doc,
} }
if ((l == 1) || (!IS_CHAR(val))) { if ((l == 1) || (!IS_CHAR(val))) {
xmlSaveErr(XML_SAVE_CHAR_INVALID, (xmlNodePtr) attr, NULL); xmlSaveErr(XML_SAVE_CHAR_INVALID, (xmlNodePtr) attr, NULL);
if (doc != NULL)
doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1");
xmlSerializeHexCharRef(tmp, *cur); xmlSerializeHexCharRef(tmp, *cur);
xmlBufAdd(buf, (xmlChar *) tmp, -1); xmlBufAdd(buf, (xmlChar *) tmp, -1);
cur++; cur++;

View file

@ -44,6 +44,12 @@
* but is done here due to performance. Move it to an other layer * but is done here due to performance. Move it to an other layer
* is schema construction via an API is implemented. * is schema construction via an API is implemented.
*/ */
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
@ -166,7 +172,7 @@ static const xmlChar *xmlNamespaceNs = (const xmlChar *)
/* /*
* Macros for attribute uses. * Macros for attribute uses.
*/ */
#define WXS_ATTRUSE_DECL(au) WXS_ATTR_CAST (WXS_ATTR_USE_CAST (au))->attrDecl #define WXS_ATTRUSE_DECL(au) (WXS_ATTR_USE_CAST (au))->attrDecl
#define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au)) #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
@ -363,6 +369,7 @@ typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr; typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
struct _xmlSchemaAbstractCtxt { struct _xmlSchemaAbstractCtxt {
int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */ int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
void *dummy; /* Fix alignment issues */
}; };
typedef struct _xmlSchemaBucket xmlSchemaBucket; typedef struct _xmlSchemaBucket xmlSchemaBucket;
@ -473,6 +480,7 @@ typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr; typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
struct _xmlSchemaBasicItem { struct _xmlSchemaBasicItem {
xmlSchemaTypeType type; xmlSchemaTypeType type;
void *dummy; /* Fix alignment issues */
}; };
/** /**
@ -1734,6 +1742,7 @@ xmlSchemaFormatItemForReport(xmlChar **buf,
*buf = xmlStrcat(*buf, BAD_CAST "'"); *buf = xmlStrcat(*buf, BAD_CAST "'");
FREE_AND_NULL(str); FREE_AND_NULL(str);
} }
/* Falls through. */
default: default:
named = 0; named = 0;
} }
@ -15890,7 +15899,7 @@ xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
* STATUS: (seems) complete * STATUS: (seems) complete
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt, xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
@ -16137,7 +16146,7 @@ xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
* (1.4.3.2.2.2) "Particle Valid (Extension)" * (1.4.3.2.2.2) "Particle Valid (Extension)"
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
@ -16394,7 +16403,7 @@ xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
* Validation Rule: Checking complex type subsumption * Validation Rule: Checking complex type subsumption
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
@ -16584,7 +16593,7 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
* (3.4.6) Constraints on Complex Type Definition Schema Components * (3.4.6) Constraints on Complex Type Definition Schema Components
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
@ -16614,7 +16623,7 @@ xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
* Complex Type Definition Representation OK (src-ct) * Complex Type Definition Representation OK (src-ct)
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
@ -16783,7 +16792,7 @@ xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
* STATUS: complete * STATUS: complete
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckParticleRangeOK(int rmin, int rmax, xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
@ -16813,7 +16822,7 @@ xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
* CLARIFY: (3.2.2) * CLARIFY: (3.2.2)
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
@ -16918,7 +16927,7 @@ xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
* STATUS: complete * STATUS: complete
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
@ -16962,7 +16971,7 @@ xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
* STATUS: TODO * STATUS: TODO
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
@ -16988,7 +16997,7 @@ xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
* STATUS: complete * STATUS: complete
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
@ -17038,7 +17047,7 @@ xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
* STATUS: TODO * STATUS: TODO
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
@ -17079,7 +17088,7 @@ xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
* STATUS: TODO: subst-groups * STATUS: TODO: subst-groups
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
@ -17134,7 +17143,7 @@ xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
* TODO: subst-groups * TODO: subst-groups
* *
* Returns 0 if the constraints are satisfied, a positive * Returns 0 if the constraints are satisfied, a positive
* error code if not and -1 if an internal error occured. * error code if not and -1 if an internal error occurred.
*/ */
static int static int
xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt, xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
@ -17764,7 +17773,7 @@ xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt,
return (0); return (0);
internal_error: internal_error:
PERROR_INT("xmlSchemaDeriveAndValidateFacets", PERROR_INT("xmlSchemaDeriveAndValidateFacets",
"an error occured"); "an error occurred");
return (-1); return (-1);
} }
@ -21413,7 +21422,7 @@ exit_failure:
ctxt->ownsConstructor = 0; ctxt->ownsConstructor = 0;
} }
PERROR_INT2("xmlSchemaParse", PERROR_INT2("xmlSchemaParse",
"An internal error occured"); "An internal error occurred");
ctxt->schema = NULL; ctxt->schema = NULL;
return(NULL); return(NULL);
} }
@ -22029,7 +22038,7 @@ xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef,
* Creates an augmented IDC definition for the imported schema. * Creates an augmented IDC definition for the imported schema.
*/ */
static void static void
xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt) { xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt, xmlChar *name ATTRIBUTE_UNUSED) {
if (imported->schema->idcDef != NULL) { if (imported->schema->idcDef != NULL) {
xmlHashScan(imported->schema->idcDef , xmlHashScan(imported->schema->idcDef ,
(xmlHashScanner) xmlSchemaAugmentIDC, vctxt); (xmlHashScanner) xmlSchemaAugmentIDC, vctxt);
@ -26094,7 +26103,7 @@ xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
/* /*
* Get hold of the still expected content, since a further * Get hold of the still expected content, since a further
* call to xmlRegExecPushString() will loose this information. * call to xmlRegExecPushString() will lose this information.
*/ */
xmlRegExecNextValues(inode->regexCtxt, xmlRegExecNextValues(inode->regexCtxt,
&nbval, &nbneg, &values[0], &terminal); &nbval, &nbneg, &values[0], &terminal);
@ -27150,7 +27159,7 @@ root_found:
} }
if (ret < 0) { if (ret < 0) {
/* /*
* VAL TODO: A reader error occured; what to do here? * VAL TODO: A reader error occurred; what to do here?
*/ */
ret = 1; ret = 1;
goto exit; goto exit;
@ -27391,6 +27400,7 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
* attributes yet. * attributes yet.
*/ */
if (nb_attributes != 0) { if (nb_attributes != 0) {
int valueLen, k, l;
xmlChar *value; xmlChar *value;
for (j = 0, i = 0; i < nb_attributes; i++, j += 5) { for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
@ -27400,12 +27410,31 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
* libxml2 differs from normal SAX here in that it escapes all ampersands * libxml2 differs from normal SAX here in that it escapes all ampersands
* as &#38; instead of delivering the raw converted string. Changing the * as &#38; instead of delivering the raw converted string. Changing the
* behavior at this point would break applications that use this API, so * behavior at this point would break applications that use this API, so
* we are forced to work around it. There is no danger of accidentally * we are forced to work around it.
* decoding some entity other than &#38; in this step because without
* unescaped ampersands there can be no other entities in the string.
*/ */
value = xmlStringLenDecodeEntities(vctxt->parserCtxt, attributes[j+3], valueLen = attributes[j+4] - attributes[j+3];
attributes[j+4] - attributes[j+3], XML_SUBSTITUTE_REF, 0, 0, 0); value = xmlMallocAtomic(valueLen + 1);
if (value == NULL) {
xmlSchemaVErrMemory(vctxt,
"allocating string for decoded attribute",
NULL);
goto internal_error;
}
for (k = 0, l = 0; k < valueLen; l++) {
if (k < valueLen - 4 &&
attributes[j+3][k+0] == '&' &&
attributes[j+3][k+1] == '#' &&
attributes[j+3][k+2] == '3' &&
attributes[j+3][k+3] == '8' &&
attributes[j+3][k+4] == ';') {
value[l] = '&';
k += 5;
} else {
value[l] = attributes[j+3][k];
k++;
}
}
value[l] = '\0';
/* /*
* TODO: Set the node line. * TODO: Set the node line.
*/ */

View file

@ -7,6 +7,11 @@
* Daniel Veillard <veillard@redhat.com> * Daniel Veillard <veillard@redhat.com>
*/ */
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
@ -5398,7 +5403,7 @@ xmlSchemaValidateFacetInternal(xmlSchemaFacetPtr facet,
if ((valType == XML_SCHEMAS_QNAME) || if ((valType == XML_SCHEMAS_QNAME) ||
(valType == XML_SCHEMAS_NOTATION)) (valType == XML_SCHEMAS_NOTATION))
return (0); return (0);
/* No break on purpose. */ /* Falls through. */
case XML_SCHEMA_FACET_MAXLENGTH: case XML_SCHEMA_FACET_MAXLENGTH:
case XML_SCHEMA_FACET_MINLENGTH: { case XML_SCHEMA_FACET_MINLENGTH: {
unsigned int len = 0; unsigned int len = 0;

View file

@ -440,8 +440,8 @@ xmlStrlen(const xmlChar *str) {
* first bytes of @add. Note that if @len < 0 then this is an API error * first bytes of @add. Note that if @len < 0 then this is an API error
* and NULL will be returned. * and NULL will be returned.
* *
* Returns a new xmlChar *, the original @cur is reallocated if needed * Returns a new xmlChar *, the original @cur is reallocated and should
* and should not be freed * not be freed.
*/ */
xmlChar * xmlChar *
@ -519,7 +519,8 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {
* encoded in UTF-8 or an encoding with 8bit based chars, we assume * encoded in UTF-8 or an encoding with 8bit based chars, we assume
* a termination mark of '0'. * a termination mark of '0'.
* *
* Returns a new xmlChar * containing the concatenated string. * Returns a new xmlChar * containing the concatenated string. The original
* @cur is reallocated and should not be freed.
*/ */
xmlChar * xmlChar *
xmlStrcat(xmlChar *cur, const xmlChar *add) { xmlStrcat(xmlChar *cur, const xmlChar *add) {
@ -822,7 +823,7 @@ xmlCheckUTF8(const unsigned char *utf)
* @len: the number of characters in the array * @len: the number of characters in the array
* *
* storage size of an UTF8 string * storage size of an UTF8 string
* the behaviour is not garanteed if the input string is not UTF-8 * the behaviour is not guaranteed if the input string is not UTF-8
* *
* Returns the storage size of * Returns the storage size of
* the first 'len' characters of ARRAY * the first 'len' characters of ARRAY

View file

@ -29,14 +29,14 @@ typedef struct {
} xmlUnicodeRange; } xmlUnicodeRange;
typedef struct { typedef struct {
xmlUnicodeRange *table; const xmlUnicodeRange *table;
int numentries; int numentries;
} xmlUnicodeNameTable; } xmlUnicodeNameTable;
static xmlIntFunc *xmlUnicodeLookup(xmlUnicodeNameTable *tptr, const char *tname); static xmlIntFunc *xmlUnicodeLookup(xmlUnicodeNameTable *tptr, const char *tname);
static xmlUnicodeRange xmlUnicodeBlocks[] = { static const xmlUnicodeRange xmlUnicodeBlocks[] = {
{"AegeanNumbers", xmlUCSIsAegeanNumbers}, {"AegeanNumbers", xmlUCSIsAegeanNumbers},
{"AlphabeticPresentationForms", xmlUCSIsAlphabeticPresentationForms}, {"AlphabeticPresentationForms", xmlUCSIsAlphabeticPresentationForms},
{"Arabic", xmlUCSIsArabic}, {"Arabic", xmlUCSIsArabic},
@ -945,7 +945,7 @@ static xmlUnicodeNameTable xmlUnicodeCatTbl = {xmlUnicodeCats, 36};
static xmlIntFunc static xmlIntFunc
*xmlUnicodeLookup(xmlUnicodeNameTable *tptr, const char *tname) { *xmlUnicodeLookup(xmlUnicodeNameTable *tptr, const char *tname) {
int low, high, mid, cmp; int low, high, mid, cmp;
xmlUnicodeRange *sptr; const xmlUnicodeRange *sptr;
if ((tptr == NULL) || (tname == NULL)) return(NULL); if ((tptr == NULL) || (tname == NULL)) return(NULL);

View file

@ -3754,6 +3754,7 @@ xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer)
if (count < 0) if (count < 0)
return -1; return -1;
sum += count; sum += count;
/* Falls through. */
case XML_TEXTWRITER_DTD_ENTY: case XML_TEXTWRITER_DTD_ENTY:
case XML_TEXTWRITER_DTD_PENT: case XML_TEXTWRITER_DTD_PENT:
count = xmlOutputBufferWriteString(writer->out, ">"); count = xmlOutputBufferWriteString(writer->out, ">");

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,11 @@
* daniel@veillard.com * daniel@veillard.com
*/ */
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML #define IN_LIBXML
#include "libxml.h" #include "libxml.h"
@ -99,6 +104,10 @@ xmlXPtrErr(xmlXPathParserContextPtr ctxt, int error,
msg, extra); msg, extra);
return; return;
} }
/* cleanup current last error */
xmlResetError(&ctxt->context->lastError);
ctxt->context->lastError.domain = XML_FROM_XPOINTER; ctxt->context->lastError.domain = XML_FROM_XPOINTER;
ctxt->context->lastError.code = error; ctxt->context->lastError.code = error;
ctxt->context->lastError.level = XML_ERR_ERROR; ctxt->context->lastError.level = XML_ERR_ERROR;
@ -319,6 +328,45 @@ xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {
return(1); return(1);
} }
/**
* xmlXPtrNewRangeInternal:
* @start: the starting node
* @startindex: the start index
* @end: the ending point
* @endindex: the ending index
*
* Internal function to create a new xmlXPathObjectPtr of type range
*
* Returns the newly created object.
*/
static xmlXPathObjectPtr
xmlXPtrNewRangeInternal(xmlNodePtr start, int startindex,
xmlNodePtr end, int endindex) {
xmlXPathObjectPtr ret;
/*
* Namespace nodes must be copied (see xmlXPathNodeSetDupNs).
* Disallow them for now.
*/
if ((start != NULL) && (start->type == XML_NAMESPACE_DECL))
return(NULL);
if ((end != NULL) && (end->type == XML_NAMESPACE_DECL))
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0, sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start;
ret->index = startindex;
ret->user2 = end;
ret->index2 = endindex;
return(ret);
}
/** /**
* xmlXPtrNewRange: * xmlXPtrNewRange:
* @start: the starting node * @start: the starting node
@ -344,17 +392,7 @@ xmlXPtrNewRange(xmlNodePtr start, int startindex,
if (endindex < 0) if (endindex < 0)
return(NULL); return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex);
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start;
ret->index = startindex;
ret->user2 = end;
ret->index2 = endindex;
xmlXPtrRangeCheckOrder(ret); xmlXPtrRangeCheckOrder(ret);
return(ret); return(ret);
} }
@ -381,17 +419,8 @@ xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) {
if (end->type != XPATH_POINT) if (end->type != XPATH_POINT)
return(NULL); return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user,
if (ret == NULL) { end->index);
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start->user;
ret->index = start->index;
ret->user2 = end->user;
ret->index2 = end->index;
xmlXPtrRangeCheckOrder(ret); xmlXPtrRangeCheckOrder(ret);
return(ret); return(ret);
} }
@ -416,17 +445,7 @@ xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) {
if (start->type != XPATH_POINT) if (start->type != XPATH_POINT)
return(NULL); return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1);
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start->user;
ret->index = start->index;
ret->user2 = end;
ret->index2 = -1;
xmlXPtrRangeCheckOrder(ret); xmlXPtrRangeCheckOrder(ret);
return(ret); return(ret);
} }
@ -453,17 +472,7 @@ xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) {
if (end->type != XPATH_POINT) if (end->type != XPATH_POINT)
return(NULL); return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index);
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start;
ret->index = -1;
ret->user2 = end->user;
ret->index2 = end->index;
xmlXPtrRangeCheckOrder(ret); xmlXPtrRangeCheckOrder(ret);
return(ret); return(ret);
} }
@ -486,17 +495,7 @@ xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) {
if (end == NULL) if (end == NULL)
return(NULL); return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start, -1, end, -1);
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start;
ret->index = -1;
ret->user2 = end;
ret->index2 = -1;
xmlXPtrRangeCheckOrder(ret); xmlXPtrRangeCheckOrder(ret);
return(ret); return(ret);
} }
@ -516,17 +515,7 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {
if (start == NULL) if (start == NULL)
return(NULL); return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1);
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start;
ret->index = -1;
ret->user2 = NULL;
ret->index2 = -1;
return(ret); return(ret);
} }
@ -541,6 +530,8 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {
*/ */
xmlXPathObjectPtr xmlXPathObjectPtr
xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) { xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
xmlNodePtr endNode;
int endIndex;
xmlXPathObjectPtr ret; xmlXPathObjectPtr ret;
if (start == NULL) if (start == NULL)
@ -549,47 +540,28 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
return(NULL); return(NULL);
switch (end->type) { switch (end->type) {
case XPATH_POINT: case XPATH_POINT:
endNode = end->user;
endIndex = end->index;
break;
case XPATH_RANGE: case XPATH_RANGE:
endNode = end->user2;
endIndex = end->index2;
break; break;
case XPATH_NODESET: case XPATH_NODESET:
/* /*
* Empty set ... * Empty set ...
*/ */
if (end->nodesetval->nodeNr <= 0) if ((end->nodesetval == NULL) || (end->nodesetval->nodeNr <= 0))
return(NULL); return(NULL);
endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];
endIndex = -1;
break; break;
default: default:
/* TODO */ /* TODO */
return(NULL); return(NULL);
} }
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject)); ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex);
if (ret == NULL) {
xmlXPtrErrMemory("allocating range");
return(NULL);
}
memset(ret, 0 , (size_t) sizeof(xmlXPathObject));
ret->type = XPATH_RANGE;
ret->user = start;
ret->index = -1;
switch (end->type) {
case XPATH_POINT:
ret->user2 = end->user;
ret->index2 = end->index;
break;
case XPATH_RANGE:
ret->user2 = end->user2;
ret->index2 = end->index2;
break;
case XPATH_NODESET: {
ret->user2 = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];
ret->index2 = -1;
break;
}
default:
STRANGE
return(NULL);
}
xmlXPtrRangeCheckOrder(ret); xmlXPtrRangeCheckOrder(ret);
return(ret); return(ret);
} }
@ -986,8 +958,10 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
if (name == NULL) if (name == NULL)
XP_ERROR(XPATH_EXPR_ERROR); XP_ERROR(XPATH_EXPR_ERROR);
if (CUR != '(') if (CUR != '(') {
xmlFree(name);
XP_ERROR(XPATH_EXPR_ERROR); XP_ERROR(XPATH_EXPR_ERROR);
}
NEXT; NEXT;
level = 1; level = 1;
@ -996,6 +970,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
buffer = (xmlChar *) xmlMallocAtomic(len * sizeof (xmlChar)); buffer = (xmlChar *) xmlMallocAtomic(len * sizeof (xmlChar));
if (buffer == NULL) { if (buffer == NULL) {
xmlXPtrErrMemory("allocating buffer"); xmlXPtrErrMemory("allocating buffer");
xmlFree(name);
return; return;
} }
@ -1020,6 +995,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
*cur = 0; *cur = 0;
if ((level != 0) && (CUR == 0)) { if ((level != 0) && (CUR == 0)) {
xmlFree(name);
xmlFree(buffer); xmlFree(buffer);
XP_ERROR(XPTR_SYNTAX_ERROR); XP_ERROR(XPTR_SYNTAX_ERROR);
} }
@ -1052,6 +1028,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
if (name2 == NULL) { if (name2 == NULL) {
CUR_PTR = left; CUR_PTR = left;
xmlFree(buffer); xmlFree(buffer);
xmlFree(name);
XP_ERROR(XPATH_EXPR_ERROR); XP_ERROR(XPATH_EXPR_ERROR);
} }
xmlXPtrEvalChildSeq(ctxt, name2); xmlXPtrEvalChildSeq(ctxt, name2);
@ -1332,8 +1309,6 @@ xmlXPtrNewContext(xmlDocPtr doc, xmlNodePtr here, xmlNodePtr origin) {
ret->here = here; ret->here = here;
ret->origin = origin; ret->origin = origin;
xmlXPathRegisterFunc(ret, (xmlChar *)"range-to",
xmlXPtrRangeToFunction);
xmlXPathRegisterFunc(ret, (xmlChar *)"range", xmlXPathRegisterFunc(ret, (xmlChar *)"range",
xmlXPtrRangeFunction); xmlXPtrRangeFunction);
xmlXPathRegisterFunc(ret, (xmlChar *)"range-inside", xmlXPathRegisterFunc(ret, (xmlChar *)"range-inside",
@ -1400,7 +1375,7 @@ xmlXPtrEval(const xmlChar *str, xmlXPathContextPtr ctx) {
*/ */
xmlNodeSetPtr set; xmlNodeSetPtr set;
set = tmp->nodesetval; set = tmp->nodesetval;
if ((set->nodeNr != 1) || if ((set == NULL) || (set->nodeNr != 1) ||
(set->nodeTab[0] != (xmlNodePtr) ctx->doc)) (set->nodeTab[0] != (xmlNodePtr) ctx->doc))
stack++; stack++;
} else } else
@ -1835,8 +1810,8 @@ xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs) {
case XPATH_RANGE: { case XPATH_RANGE: {
xmlNodePtr node = tmp->user; xmlNodePtr node = tmp->user;
if (node != NULL) { if (node != NULL) {
if (node->type == XML_ATTRIBUTE_NODE) { if ((node->type == XML_ATTRIBUTE_NODE) ||
/* TODO: Namespace Nodes ??? */ (node->type == XML_NAMESPACE_DECL)) {
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
xmlXPtrFreeLocationSet(newset); xmlXPtrFreeLocationSet(newset);
XP_ERROR(XPTR_SYNTAX_ERROR); XP_ERROR(XPTR_SYNTAX_ERROR);
@ -1931,8 +1906,8 @@ xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs) {
case XPATH_RANGE: { case XPATH_RANGE: {
xmlNodePtr node = tmp->user2; xmlNodePtr node = tmp->user2;
if (node != NULL) { if (node != NULL) {
if (node->type == XML_ATTRIBUTE_NODE) { if ((node->type == XML_ATTRIBUTE_NODE) ||
/* TODO: Namespace Nodes ??? */ (node->type == XML_NAMESPACE_DECL)) {
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
xmlXPtrFreeLocationSet(newset); xmlXPtrFreeLocationSet(newset);
XP_ERROR(XPTR_SYNTAX_ERROR); XP_ERROR(XPTR_SYNTAX_ERROR);
@ -2073,9 +2048,11 @@ xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathFreeObject(set); xmlXPathFreeObject(set);
XP_ERROR(XPATH_MEMORY_ERROR); XP_ERROR(XPATH_MEMORY_ERROR);
} }
for (i = 0;i < oldset->locNr;i++) { if (oldset != NULL) {
xmlXPtrLocationSetAdd(newset, for (i = 0;i < oldset->locNr;i++) {
xmlXPtrCoveringRange(ctxt, oldset->locTab[i])); xmlXPtrLocationSetAdd(newset,
xmlXPtrCoveringRange(ctxt, oldset->locTab[i]));
}
} }
/* /*
@ -2243,76 +2220,14 @@ xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs) {
* @nargs: the number of args * @nargs: the number of args
* *
* Implement the range-to() XPointer function * Implement the range-to() XPointer function
*
* Obsolete. range-to is not a real function but a special type of location
* step which is handled in xpath.c.
*/ */
void void
xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt,
xmlXPathObjectPtr range; int nargs ATTRIBUTE_UNUSED) {
const xmlChar *cur; XP_ERROR(XPATH_EXPR_ERROR);
xmlXPathObjectPtr res, obj;
xmlXPathObjectPtr tmp;
xmlLocationSetPtr newset = NULL;
xmlNodeSetPtr oldset;
int i;
if (ctxt == NULL) return;
CHECK_ARITY(1);
/*
* Save the expression pointer since we will have to evaluate
* it multiple times. Initialize the new set.
*/
CHECK_TYPE(XPATH_NODESET);
obj = valuePop(ctxt);
oldset = obj->nodesetval;
ctxt->context->node = NULL;
cur = ctxt->cur;
newset = xmlXPtrLocationSetCreate(NULL);
for (i = 0; i < oldset->nodeNr; i++) {
ctxt->cur = cur;
/*
* Run the evaluation with a node list made of a single item
* in the nodeset.
*/
ctxt->context->node = oldset->nodeTab[i];
tmp = xmlXPathNewNodeSet(ctxt->context->node);
valuePush(ctxt, tmp);
xmlXPathEvalExpr(ctxt);
CHECK_ERROR;
/*
* The result of the evaluation need to be tested to
* decided whether the filter succeeded or not
*/
res = valuePop(ctxt);
range = xmlXPtrNewRangeNodeObject(oldset->nodeTab[i], res);
if (range != NULL) {
xmlXPtrLocationSetAdd(newset, range);
}
/*
* Cleanup
*/
if (res != NULL)
xmlXPathFreeObject(res);
if (ctxt->value == tmp) {
res = valuePop(ctxt);
xmlXPathFreeObject(res);
}
ctxt->context->node = NULL;
}
/*
* The result is used as the new evaluation set.
*/
xmlXPathFreeObject(obj);
ctxt->context->node = NULL;
ctxt->context->contextSize = -1;
ctxt->context->proximityPosition = -1;
valuePush(ctxt, xmlXPtrWrapLocationSet(newset));
} }
/** /**

View file

@ -408,7 +408,7 @@ xz_head(xz_statep state)
state->strm = init; state->strm = init;
state->strm.avail_in = 0; state->strm.avail_in = 0;
state->strm.next_in = NULL; state->strm.next_in = NULL;
if (lzma_auto_decoder(&state->strm, UINT64_MAX, 0) != LZMA_OK) { if (lzma_auto_decoder(&state->strm, 100000000, 0) != LZMA_OK) {
xmlFree(state->out); xmlFree(state->out);
xmlFree(state->in); xmlFree(state->in);
state->size = 0; state->size = 0;
@ -797,6 +797,8 @@ __libxml2_xzclose(xzFile file)
xmlFree(state->in); xmlFree(state->in);
} }
xmlFree(state->path); xmlFree(state->path);
if ((state->msg != NULL) && (state->err != LZMA_MEM_ERROR))
xmlFree(state->msg);
ret = close(state->fd); ret = close(state->fd);
xmlFree(state); xmlFree(state);
return ret ? ret : LZMA_OK; return ret ? ret : LZMA_OK;