[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
htmlParseDocument(htmlParserCtxtPtr ctxt);
XMLPUBFUN htmlDocPtr XMLCALL
htmlSAXParseDoc (xmlChar *cur,
htmlSAXParseDoc (const xmlChar *cur,
const char *encoding,
htmlSAXHandlerPtr sax,
void *userData);
XMLPUBFUN htmlDocPtr XMLCALL
htmlParseDoc (xmlChar *cur,
htmlParseDoc (const xmlChar *cur,
const char *encoding);
XMLPUBFUN htmlDocPtr XMLCALL
htmlSAXParseFile(const char *filename,

View file

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

View file

@ -3,7 +3,7 @@
* Description: internal interfaces for the XML Schemas handling
* and schema validity checking
* 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.
*

View file

@ -72,8 +72,13 @@ XMLPUBFUN void XMLCALL
XMLPUBFUN xmlGlobalStatePtr XMLCALL
xmlGetGlobalState(void);
#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && defined(LIBXML_STATIC_FOR_DLL)
int XMLCALL xmlDllMain(void *hinstDLL, unsigned long fdwReason, void *lpvReserved);
#ifdef HAVE_PTHREAD_H
#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
#ifdef __cplusplus

View file

@ -393,7 +393,7 @@ typedef void * xmlTextReaderLocatorPtr;
* @arg: the user argument
* @msg: the message
* @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
*/

View file

@ -29,28 +29,28 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version);
*
* the version string like "1.2.3"
*/
#define LIBXML_DOTTED_VERSION "2.9.4"
#define LIBXML_DOTTED_VERSION "2.9.7"
/**
* LIBXML_VERSION:
*
* the version number: 1.2.3 value is 10203
*/
#define LIBXML_VERSION 20904
#define LIBXML_VERSION 20907
/**
* LIBXML_VERSION_STRING:
*
* the version number string, 1.2.3 value is "10203"
*/
#define LIBXML_VERSION_STRING "20904"
#define LIBXML_VERSION_STRING "20907"
/**
* LIBXML_VERSION_EXTRA:
*
* 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:
@ -58,7 +58,7 @@ XMLPUBFUN void XMLCALL xmlCheckVersion(int version);
* Macro to check that the libxml version in use is compatible with
* the version the software has been compiled against
*/
#define LIBXML_TEST_VERSION xmlCheckVersion(20904);
#define LIBXML_TEST_VERSION xmlCheckVersion(20907);
#ifndef VMS
#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 "*"
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.
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
"strict" lookup for namespaces based on a prefix. Fixed a
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>
@ -3951,7 +3951,7 @@ Thu Jun 30 15:01:52 CEST 2005 Daniel Veillard <daniel@veillard.com>
* README: updated
* debugXML.c: fix a bug raised by bill on IRC
* 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
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
the build of the pre-computed substitution groups. Channeled
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
the attribute did not resolve to an IDC field (discovered
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>
* 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):
a variable was missed to be reset in a loop. Deactivated bubbling,
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
Clark it appeared I had bug in URI parsing code ...
* 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
* 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
* python/generator.py python/setup.py.in: applied cleanup
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
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>
* 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.
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>
* 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>

View file

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

View file

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stddef.h>
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
@ -1181,6 +1182,8 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElement");
if (name != NULL)
xmlFree(name);
if (nval != NULL)
xmlFree(nval);
return;
}
} else {
@ -1242,6 +1245,8 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
xmlFree(ns);
if (name != NULL)
xmlFree(name);
if (nval != NULL)
xmlFree(nval);
return;
}
} else {
@ -1311,6 +1316,8 @@ xmlSAX2AttributeInternal(void *ctx, const xmlChar *fullname,
name, namespace->href);
ctxt->wellFormed = 0;
if (ctxt->recovery == 0) ctxt->disableSAX = 1;
if (name != NULL)
xmlFree(name);
goto error;
}
}
@ -1908,7 +1915,7 @@ skip:
else {
ret->line = 65535;
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 {
/*
* 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
*/
continue;
@ -2805,7 +2812,8 @@ xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len)
xmlTextConcat(lastChild, value, len);
} else {
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 size; /* The buffer size */
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
@ -231,7 +231,7 @@ xmlBufPtr
xmlBufCreateStatic(void *mem, size_t size) {
xmlBufPtr ret;
if ((mem == NULL) || (size == 0))
if (mem == NULL)
return(NULL);
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
* 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

View file

@ -1375,13 +1375,6 @@ xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur)
xmlFreeURI(uri);
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);
}
ns = ns->next;

View file

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

View file

@ -275,8 +275,7 @@
/* Define as const if the declaration of iconv() needs 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 */
/* Name of package */
@ -323,9 +322,6 @@
#define below would cause a syntax error. */
/* #undef _UINT32_T */
/* Using the Win32 Socket implementation */
//#define _WINSOCKAPI_ 1
/* ss_family is not defined here, use __ss_family instead */
/* #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");
#endif /* LIBXML_VALID_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
fprintf(ctxt->output, "\tgrep string search for a string in the subtree\n");
#ifdef LIBXML_VALID_ENABLED

View file

@ -48,7 +48,7 @@
#else
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#elif defined(WIN32)
#elif defined(_WIN32)
typedef unsigned __int32 uint32_t;
#endif
#endif
@ -249,7 +249,7 @@ xmlDictAddString(xmlDictPtr dict, const xmlChar *name, unsigned int namelen) {
#endif
pool = dict->strings;
while (pool != NULL) {
if (pool->end - pool->free > namelen)
if ((size_t)(pool->end - pool->free) > namelen)
goto found_pool;
if (pool->size > size) size = pool->size;
limit += pool->size;
@ -317,7 +317,7 @@ xmlDictAddQString(xmlDictPtr dict, const xmlChar *prefix, unsigned int plen,
#endif
pool = dict->strings;
while (pool != NULL) {
if (pool->end - pool->free > namelen + plen + 1)
if ((size_t)(pool->end - pool->free) > namelen + plen + 1)
goto found_pool;
if (pool->size > size) size = pool->size;
limit += pool->size;
@ -453,14 +453,23 @@ xmlDictComputeFastKey(const xmlChar *name, int namelen, int seed) {
}
switch (namelen) {
case 10: value += name[9];
/* Falls through. */
case 9: value += name[8];
/* Falls through. */
case 8: value += name[7];
/* Falls through. */
case 7: value += name[6];
/* Falls through. */
case 6: value += name[5];
/* Falls through. */
case 5: value += name[4];
/* Falls through. */
case 4: value += name[3];
/* Falls through. */
case 3: value += name[2];
/* Falls through. */
case 2: value += name[1];
/* Falls through. */
default: break;
}
return(value);
@ -496,15 +505,25 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
}
switch (plen) {
case 10: value += prefix[9];
/* Falls through. */
case 9: value += prefix[8];
/* Falls through. */
case 8: value += prefix[7];
/* Falls through. */
case 7: value += prefix[6];
/* Falls through. */
case 6: value += prefix[5];
/* Falls through. */
case 5: value += prefix[4];
/* Falls through. */
case 4: value += prefix[3];
/* Falls through. */
case 3: value += prefix[2];
/* Falls through. */
case 2: value += prefix[1];
/* Falls through. */
case 1: value += prefix[0];
/* Falls through. */
default: break;
}
len -= plen;
@ -514,15 +533,25 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
}
switch (len) {
case 10: value += name[9];
/* Falls through. */
case 9: value += name[8];
/* Falls through. */
case 8: value += name[7];
/* Falls through. */
case 7: value += name[6];
/* Falls through. */
case 6: value += name[5];
/* Falls through. */
case 5: value += name[4];
/* Falls through. */
case 4: value += name[3];
/* Falls through. */
case 3: value += name[2];
/* Falls through. */
case 2: value += name[1];
/* Falls through. */
case 1: value += name[0];
/* Falls through. */
default: break;
}
return(value);
@ -533,7 +562,7 @@ xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
*
* 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
xmlDictCreate(void) {
@ -580,7 +609,7 @@ xmlDictCreate(void) {
* new dictionary, then in @sub, and if not found are created in the
* 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
xmlDictCreateSub(xmlDictPtr sub) {
@ -699,7 +728,7 @@ xmlDictGrow(xmlDictPtr dict, size_t size) {
} else {
/*
* 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;
}

View file

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

View file

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

View file

@ -6,6 +6,11 @@
* daniel@veillard.com
*/
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML
#include "libxml.h"
@ -649,7 +654,7 @@ xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
} else if (*cur >= 0x80) {
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;
xc = (*cur & 0x3F) << 6;
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
* 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
xmlGetLastError(void)
@ -910,7 +910,7 @@ xmlResetLastError(void)
*
* 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
xmlCtxtGetLastError(void *ctx)

View file

@ -168,7 +168,7 @@ xmlHashComputeQKey(xmlHashTablePtr table,
*
* 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
xmlHashCreate(int size) {
@ -202,7 +202,7 @@ xmlHashCreate(int size) {
*
* 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
xmlHashCreateDict(int size, xmlDictPtr dict) {

View file

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

View file

@ -8,7 +8,7 @@
#ifdef _WIN32_WCE
#include <winsock.h>
#else
#undef HAVE_ERRNO_H
#include <errno.h>
#include <winsock2.h>
/* the following is a workaround a problem for 'inline' keyword in said
@ -27,60 +27,23 @@
#endif
#endif
#if defined( __MINGW32__ ) || defined( _MSC_VER )
/* Include <errno.h> here to ensure that it doesn't get included later
* (e.g. by iconv.h) and overwrites the definition of EWOULDBLOCK. */
#include <errno.h>
#undef EWOULDBLOCK
#undef XML_SOCKLEN_T
#define XML_SOCKLEN_T int
#ifndef ECONNRESET
#define ECONNRESET WSAECONNRESET
#endif
#if !defined SOCKLEN_T
#define SOCKLEN_T int
#ifndef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#endif
#ifndef EINTR
#define EINTR WSAEINTR
#endif
#ifndef ESHUTDOWN
#define ESHUTDOWN WSAESHUTDOWN
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#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__ */

View file

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

View file

@ -347,7 +347,7 @@ void xmlListDelete(xmlListPtr l)
*
* 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
xmlListRemoveFirst(xmlListPtr l, void *data)
@ -372,7 +372,7 @@ xmlListRemoveFirst(xmlListPtr l, void *data)
*
* 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
xmlListRemoveLast(xmlListPtr l, void *data)

View file

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

View file

@ -11,7 +11,6 @@
* daniel@veillard.com
*/
#define NEED_SOCKETS
#define IN_LIBXML
#include "libxml.h"
@ -74,14 +73,8 @@
#define XML_SOCKLEN_T unsigned int
#endif
#if defined(__MINGW32__) || defined(_WIN32_WCE)
/*#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_
#endif*/
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <wsockcompat.h>
#include <winsock2.h>
#undef XML_SOCKLEN_T
#define XML_SOCKLEN_T unsigned int
#endif
#include <libxml/globals.h>
@ -182,7 +175,21 @@ xmlHTTPErrMemory(const char *extra)
*/
static int socket_errno(void) {
#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
return(errno);
#endif
@ -629,7 +636,7 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
#if defined(EINTR)
&& (errno != EINTR)
&& (socket_errno() != EINTR)
#endif
)
return (0);
@ -1038,16 +1045,13 @@ xmlNanoHTTPConnectAttempt(struct sockaddr *addr)
static SOCKET
xmlNanoHTTPConnectHost(const char *host, int port)
{
struct hostent *h;
struct sockaddr *addr = NULL;
struct in_addr ia;
struct sockaddr_in sockin;
#ifdef SUPPORT_IP6
struct in6_addr ia6;
struct sockaddr_in6 sockin6;
#endif
int i;
SOCKET s;
memset (&sockin, 0, sizeof(sockin));
@ -1084,7 +1088,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
for (res = result; res; res = res->ai_next) {
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");
freeaddrinfo (result);
return INVALID_SOCKET;
@ -1094,7 +1098,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
addr = (struct sockaddr *)&sockin;
#ifdef SUPPORT_IP6
} 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");
freeaddrinfo (result);
return INVALID_SOCKET;
@ -1122,6 +1126,10 @@ xmlNanoHTTPConnectHost(const char *host, int port)
#endif
#if !defined(HAVE_GETADDRINFO) || !defined(_WIN32)
{
struct hostent *h;
struct in_addr ia;
int i;
h = gethostbyname (GETHOSTBYNAME_ARG_CAST host);
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
* 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 = "";
switch (h_errno) {
@ -1423,9 +1431,9 @@ retry:
if (ctxt->port != 80) {
/* reserve space for ':xxxxx', incl. potential proxy */
if (proxy)
blen += 12;
blen += 17;
else
blen += 6;
blen += 11;
}
bp = (char*)xmlMallocAtomic(blen);
if ( bp == NULL ) {
@ -1534,7 +1542,8 @@ retry:
xmlGenericError(xmlGenericErrorContext,
"\nRedirect to: %s\n", ctxt->location);
#endif
while ( xmlNanoHTTPRecv(ctxt) > 0 ) ;
while ( xmlNanoHTTPRecv(ctxt) > 0 )
;
if (nbRedirects < XML_NANO_HTTP_MAX_REDIR) {
nbRedirects++;
if (redirURL != NULL)

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,7 @@
#define IN_LIBXML
#include "libxml.h"
#if defined(WIN32) && !defined (__CYGWIN__)
#if defined(_WIN32) && !defined (__CYGWIN__)
#define XML_DIR_SEP '\\'
#else
#define XML_DIR_SEP '/'
@ -435,8 +435,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
if ((ctxt->instate != XML_PARSER_COMMENT))
xmlPopInput(ctxt);
return;
}
@ -470,8 +468,8 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
c = *cur;
if (c & 0x80) {
if (c == 0xC0)
goto encoding_error;
if (c == 0xC0)
goto encoding_error;
if (cur[1] == 0) {
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
cur = ctxt->input->cur;
@ -523,8 +521,6 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
ctxt->input->cur++;
ctxt->nbChars++;
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
} else {
/*
* Assume it's a fixed length encoding (1) with
@ -538,14 +534,9 @@ xmlNextChar(xmlParserCtxtPtr ctxt)
ctxt->input->col++;
ctxt->input->cur++;
ctxt->nbChars++;
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
}
if ((*ctxt->input->cur == '%') && (!ctxt->html))
xmlParserHandlePEReference(ctxt);
if ((*ctxt->input->cur == 0) &&
(xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
xmlPopInput(ctxt);
if (*ctxt->input->cur == 0)
xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
return;
encoding_error:
/*
@ -1101,8 +1092,15 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
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);
}
ctxt->charset = XML_CHAR_ENCODING_UTF8;
ret = xmlSwitchToEncodingInt(ctxt, handler, len);
if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
@ -1226,6 +1224,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
*/
nbchars = xmlCharEncFirstLineInput(input->buf, len);
}
xmlBufResetInput(input->buf->buffer, input);
if (nbchars < 0) {
xmlErrInternal(ctxt,
"switching encoding: encoder error\n",
@ -1233,7 +1232,6 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
return (-1);
}
input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
xmlBufResetInput(input->buf->buffer, input);
}
return (0);
} else if (input->length == 0) {

View file

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

View file

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

View file

@ -27,6 +27,7 @@
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#elif defined HAVE_WIN32_THREADS
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h>
#ifndef HAVE_COMPILER_TLS
#include <process.h>
@ -48,47 +49,27 @@
static int libxml_is_threaded = -1;
#if defined(__GNUC__) && defined(__GLIBC__)
#ifdef linux
#ifdef __linux__
#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 3)
extern int pthread_once (pthread_once_t *__once_control,
void (*__init_routine) (void))
__attribute((weak));
extern void *pthread_getspecific (pthread_key_t __key)
__attribute((weak));
extern int pthread_setspecific (pthread_key_t __key,
__const void *__pointer)
__attribute((weak));
extern int pthread_key_create (pthread_key_t *__key,
void (*__destr_function) (void *))
__attribute((weak));
extern int pthread_key_delete (pthread_key_t __key)
__attribute((weak));
extern int pthread_mutex_init ()
__attribute((weak));
extern int pthread_mutex_destroy ()
__attribute((weak));
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));
#pragma weak pthread_once
#pragma weak pthread_getspecific
#pragma weak pthread_setspecific
#pragma weak pthread_key_create
#pragma weak pthread_key_delete
#pragma weak pthread_mutex_init
#pragma weak pthread_mutex_destroy
#pragma weak pthread_mutex_lock
#pragma weak pthread_mutex_unlock
#pragma weak pthread_cond_init
#pragma weak pthread_cond_destroy
#pragma weak pthread_cond_wait
#pragma weak pthread_equal
#pragma weak pthread_self
#pragma weak pthread_key_create
#pragma weak pthread_key_delete
#pragma weak pthread_cond_signal
#endif
#endif /* linux */
#endif /* __linux__ */
#endif /* defined(__GNUC__) && defined(__GLIBC__) */
#endif /* HAVE_PTHREAD_H */
@ -158,7 +139,7 @@ static DWORD globalkey = TLS_OUT_OF_INDEXES;
static DWORD mainthread;
static struct {
DWORD done;
DWORD control;
LONG control;
} run_once = { 0, 0};
static volatile LPCRITICAL_SECTION global_init_lock = NULL;
@ -458,7 +439,8 @@ __xmlGlobalInitMutexLock(void)
/* Swap it into the global_init_lock */
#ifdef InterlockedCompareExchangePointer
InterlockedCompareExchangePointer(&global_init_lock, cs, NULL);
InterlockedCompareExchangePointer((void **) &global_init_lock,
cs, NULL);
#else /* Use older void* version */
InterlockedCompareExchange((void **) &global_init_lock,
(void *) cs, NULL);
@ -999,11 +981,23 @@ xmlOnceInit(void)
#ifdef HAVE_PTHREAD_H
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
#if defined(LIBXML_STATIC_FOR_DLL)
BOOL XMLCALL
xmlDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
int XMLCALL
xmlDllMain(ATTRIBUTE_UNUSED void *hinstDLL, unsigned long fdwReason,
ATTRIBUTE_UNUSED void *lpvReserved)
#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
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
DllMain(ATTRIBUTE_UNUSED HINSTANCE hinstDLL, DWORD fdwReason,
ATTRIBUTE_UNUSED LPVOID lpvReserved)
#endif
{
switch (fdwReason) {

View file

@ -1,90 +1,44 @@
/*
* taken from https://github.com/swenson/sort
* Kept as is for the moment to be able to apply upstream patches for that
* code, currently used only to speed up XPath node sorting, see xpath.c
* Taken from https://github.com/swenson/sort
* Revision: 05fd77bfec049ce8b7c408c4d3dd2d51ee061a15
* 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:
Copyright (c) 2010 Christopher Swenson
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:
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.
*/
* The MIT License (MIT)
*
* Copyright (c) 2010-2017 Christopher Swenson.
* Copyright (c) 2012 Vojtech Fried.
* Copyright (c) 2012 Google Inc. All Rights Reserved.
*
* 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:
*
* 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 <stdio.h>
#include <string.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#elif defined(WIN32)
typedef __int64 int64_t;
#elif defined(_WIN32)
typedef unsigned __int64 uint64_t;
#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
#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))
#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;}
/* 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_MAKE_STR1(x, y) SORT_CONCAT(x,y)
#define SORT_MAKE_STR(x) SORT_MAKE_STR1(SORT_NAME,x)
#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 SORT_MAKE_STR(binary_insertion_sort)
#define REVERSE_ELEMENTS SORT_MAKE_STR(reverse_elements)
#define COUNT_RUN SORT_MAKE_STR(count_run)
#define CHECK_INVARIANT SORT_MAKE_STR(check_invariant)
#define TIM_SORT SORT_MAKE_STR(tim_sort)
#define TIM_SORT_RESIZE SORT_MAKE_STR(tim_sort_resize)
#define TIM_SORT_MERGE SORT_MAKE_STR(tim_sort_merge)
#define TIM_SORT_COLLAPSE SORT_MAKE_STR(tim_sort_collapse)
#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 SORT_MAKE_STR(binary_insertion_sort)
#define REVERSE_ELEMENTS SORT_MAKE_STR(reverse_elements)
#define COUNT_RUN SORT_MAKE_STR(count_run)
#define CHECK_INVARIANT SORT_MAKE_STR(check_invariant)
#define TIM_SORT SORT_MAKE_STR(tim_sort)
#define TIM_SORT_RESIZE SORT_MAKE_STR(tim_sort_resize)
#define TIM_SORT_MERGE SORT_MAKE_STR(tim_sort_merge)
#define TIM_SORT_COLLAPSE SORT_MAKE_STR(tim_sort_collapse)
#define TIM_SORT_RUN_T SORT_MAKE_STR(tim_sort_run_t)
#define TEMP_STORAGE_T SORT_MAKE_STR(temp_storage_t)
#ifndef MAX
#define MAX(x,y) (((x) > (y) ? (x) : (y)))
#endif
#ifndef MIN
#define MIN(x,y) (((x) < (y) ? (x) : (y)))
#endif
typedef struct {
int64_t start;
int64_t length;
size_t start;
size_t length;
} TIM_SORT_RUN_T;
void BINARY_INSERTION_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 */
static int64_t BINARY_INSERTION_FIND(SORT_TYPE *dst, const SORT_TYPE x, const size_t size)
{
int64_t l, c, r;
SORT_TYPE lx;
static __inline size_t BINARY_INSERTION_FIND(SORT_TYPE *dst, const SORT_TYPE x,
const size_t size) {
size_t l, c, r;
SORT_TYPE cx;
l = 0;
r = size - 1;
c = r >> 1;
lx = dst[l];
/* check for beginning conditions */
if (SORT_CMP(x, lx) < 0)
/* check for out of bounds at the beginning. */
if (SORT_CMP(x, dst[0]) < 0) {
return 0;
else if (SORT_CMP(x, lx) == 0)
{
int64_t i = 1;
while (SORT_CMP(x, dst[i]) == 0) i++;
return i;
} else if (SORT_CMP(x, dst[r]) > 0) {
return r;
}
cx = dst[c];
while (1)
{
while (1) {
const int val = SORT_CMP(x, cx);
if (val < 0)
{
if (c - l <= 1) return c;
if (val < 0) {
if (c - l <= 1) {
return c;
}
r = c;
}
else if (val > 0)
{
if (r - c <= 1) return c + 1;
} else { /* allow = for stability. The binary search favors the right. */
if (r - c <= 1) {
return c + 1;
}
l = c;
lx = cx;
}
else
{
do
{
cx = dst[++c];
} while (SORT_CMP(x, cx) == 0);
return c;
}
c = l + ((r - l) >> 1);
cx = dst[c];
}
}
/* 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)
{
int64_t i;
for (i = start; i < (int64_t) size; i++)
{
int64_t j;
static void BINARY_INSERTION_SORT_START(SORT_TYPE *dst, const size_t start, const size_t size) {
size_t i;
for (i = start; i < size; i++) {
size_t j;
SORT_TYPE x;
int64_t location;
size_t location;
/* 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 */
x = dst[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];
if (j == 0) { /* check edge case because j is unsigned */
break;
}
}
dst[location] = x;
}
}
/* 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);
}
/* timsort implementation, based on timsort.txt */
static void REVERSE_ELEMENTS(SORT_TYPE *dst, int64_t start, int64_t end)
{
while (1)
{
if (start >= end) return;
static __inline void REVERSE_ELEMENTS(SORT_TYPE *dst, size_t start, size_t end) {
while (1) {
if (start >= end) {
return;
}
SORT_SWAP(dst[start], dst[end]);
start++;
end--;
}
}
static int64_t COUNT_RUN(SORT_TYPE *dst, const int64_t start, const size_t size)
{
int64_t curr;
if (size - start == 1) return 1;
if (start >= (int64_t) size - 2)
{
if (SORT_CMP(dst[size - 2], dst[size - 1]) > 0)
static size_t COUNT_RUN(SORT_TYPE *dst, const size_t start, const size_t size) {
size_t curr;
if (size - start == 1) {
return 1;
}
if (start >= size - 2) {
if (SORT_CMP(dst[size - 2], dst[size - 1]) > 0) {
SORT_SWAP(dst[size - 2], dst[size - 1]);
}
return 2;
}
curr = start + 2;
if (SORT_CMP(dst[start], dst[start + 1]) <= 0)
{
if (SORT_CMP(dst[start], dst[start + 1]) <= 0) {
/* increasing run */
while (1)
{
if (curr == (int64_t) size - 1) break;
if (SORT_CMP(dst[curr - 1], dst[curr]) > 0) break;
while (1) {
if (curr == size - 1) {
break;
}
if (SORT_CMP(dst[curr - 1], dst[curr]) > 0) {
break;
}
curr++;
}
return curr - start;
}
else
{
} else {
/* decreasing run */
while (1)
{
if (curr == (int64_t) size - 1) break;
if (SORT_CMP(dst[curr - 1], dst[curr]) <= 0) break;
while (1) {
if (curr == size - 1) {
break;
}
if (SORT_CMP(dst[curr - 1], dst[curr]) <= 0) {
break;
}
curr++;
}
/* reverse in-place */
REVERSE_ELEMENTS(dst, start, curr - 1);
return curr - start;
}
}
#define PUSH_NEXT() do {\
len = COUNT_RUN(dst, curr, size);\
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) {
size_t A, B, C;
static int CHECK_INVARIANT(TIM_SORT_RUN_T *stack, const int stack_curr)
{
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;
if (stack_curr < 2) {
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;
B = stack[stack_curr - 2].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;
}
@ -315,86 +353,78 @@ typedef struct {
SORT_TYPE *storage;
} TEMP_STORAGE_T;
static void TIM_SORT_RESIZE(TEMP_STORAGE_T *store, const size_t new_size)
{
if (store->alloc < new_size)
{
static void TIM_SORT_RESIZE(TEMP_STORAGE_T *store, const size_t new_size) {
if (store->alloc < new_size) {
SORT_TYPE *tempstore = (SORT_TYPE *)realloc(store->storage, new_size * sizeof(SORT_TYPE));
if (tempstore == NULL)
{
fprintf(stderr, "Error allocating temporary storage for tim sort: need %lu bytes", sizeof(SORT_TYPE) * new_size);
if (tempstore == NULL) {
fprintf(stderr, "Error allocating temporary storage for tim sort: need %lu bytes",
(unsigned long)(sizeof(SORT_TYPE) * new_size));
exit(1);
}
store->storage = tempstore;
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)
{
const int64_t A = stack[stack_curr - 2].length;
const int64_t B = stack[stack_curr - 1].length;
const int64_t curr = stack[stack_curr - 2].start;
static void TIM_SORT_MERGE(SORT_TYPE *dst, const TIM_SORT_RUN_T *stack, const int stack_curr,
TEMP_STORAGE_T *store) {
const size_t A = stack[stack_curr - 2].length;
const size_t B = stack[stack_curr - 1].length;
const size_t curr = stack[stack_curr - 2].start;
SORT_TYPE *storage;
int64_t i, j, k;
size_t i, j, k;
TIM_SORT_RESIZE(store, MIN(A, B));
storage = store->storage;
/* left merge */
if (A < B)
{
if (A < B) {
memcpy(storage, &dst[curr], A * sizeof(SORT_TYPE));
i = 0;
j = curr + A;
for (k = curr; k < curr + A + B; k++)
{
if ((i < A) && (j < curr + A + B))
{
if (SORT_CMP(storage[i], dst[j]) <= 0)
for (k = curr; k < curr + A + B; k++) {
if ((i < A) && (j < curr + A + B)) {
if (SORT_CMP(storage[i], dst[j]) <= 0) {
dst[k] = storage[i++];
else
} else {
dst[k] = dst[j++];
}
else if (i < A)
{
}
} else if (i < A) {
dst[k] = storage[i++];
} else {
break;
}
else
dst[k] = dst[j++];
}
}
/* right merge */
else
{
} else {
/* right merge */
memcpy(storage, &dst[curr + A], B * sizeof(SORT_TYPE));
i = B - 1;
j = curr + A - 1;
i = B;
j = curr + A;
k = curr + A + B;
for (k = curr + A + B - 1; k >= curr; k--)
{
if ((i >= 0) && (j >= curr))
{
if (SORT_CMP(dst[j], storage[i]) > 0)
dst[k] = dst[j--];
else
dst[k] = storage[i--];
while (k-- > curr) {
if ((i > 0) && (j > curr)) {
if (SORT_CMP(dst[j - 1], storage[i - 1]) > 0) {
dst[k] = dst[--j];
} 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) {
int64_t A, B, C, D;
int ABC, BCD, BD, CD;
size_t A, B, C, D;
int ABC, BCD, CD;
/* if the stack only has one thing on it, we are done with the collapse */
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;
CD = (C <= D);
BD = (B < D);
/* Both invariants are good */
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;
}
void TIM_SORT(SORT_TYPE *dst, const size_t size)
{
int minrun;
TEMP_STORAGE_T _store, *store;
TIM_SORT_RUN_T run_stack[128];
int stack_curr = 0;
int64_t len, run;
int64_t curr = 0;
static __inline int PUSH_NEXT(SORT_TYPE *dst,
const size_t size,
TEMP_STORAGE_T *store,
const size_t minrun,
TIM_SORT_RUN_T *run_stack,
size_t *stack_curr,
size_t *curr) {
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);
return;
}
/* compute the minimum run length */
minrun = compute_minrun(size);
/* temporary storage for merges */
store = &_store;
store->alloc = 0;
store->storage = NULL;
PUSH_NEXT();
PUSH_NEXT();
PUSH_NEXT();
if (!PUSH_NEXT(dst, size, store, minrun, run_stack, &stack_curr, &curr)) {
return;
}
while (1)
{
if (!CHECK_INVARIANT(run_stack, stack_curr))
{
if (!PUSH_NEXT(dst, size, store, minrun, run_stack, &stack_curr, &curr)) {
return;
}
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);
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
#include "libxml.h"
#include <string.h> /* for memset() only ! */
#include <stddef.h>
#include <limits.h>
#ifdef HAVE_CTYPE_H
#include <ctype.h>
@ -254,10 +260,10 @@ xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix,
*
* [NS 7] LocalPart ::= NCName
*
* Returns NULL if not a QName, otherwise the local part, and prefix
* is updated to get the Prefix if any.
* Returns NULL if the name doesn't have a prefix. Otherwise, returns the
* local part, and prefix is updated to get the Prefix. Both the return value
* and the prefix must be freed by the caller.
*/
xmlChar *
xmlSplitQName2(const xmlChar *name, xmlChar **prefix) {
int len = 0;
@ -1401,6 +1407,8 @@ xmlStringLenGetNodeList(const xmlDoc *doc, const xmlChar *value, int len) {
else if ((ent != NULL) && (ent->children == NULL)) {
xmlNodePtr temp;
/* Set to non-NULL value to avoid recursion. */
ent->children = (xmlNodePtr) -1;
ent->children = xmlStringGetNodeList(doc,
(const xmlChar*)node->content);
ent->owner = 1;
@ -1593,6 +1601,7 @@ xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) {
else if ((ent != NULL) && (ent->children == NULL)) {
xmlNodePtr temp;
/* Set to non-NULL value to avoid recursion. */
ent->children = (xmlNodePtr) -1;
ent->children = xmlStringGetNodeList(doc,
(const xmlChar*)node->content);
@ -1600,6 +1609,7 @@ xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) {
temp = ent->children;
while (temp) {
temp->parent = (xmlNodePtr)ent;
ent->last = temp;
temp = temp->next;
}
}
@ -4596,7 +4606,7 @@ xmlGetLineNoInternal(const xmlNode *node, int depth)
(node->type == XML_PI_NODE)) {
if (node->line == 65535) {
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) &&
(node->children != NULL))
result = xmlGetLineNoInternal(node->children, depth + 1);
@ -4755,8 +4765,8 @@ xmlGetNodePath(const xmlNode *node)
if (occur == 0) {
tmp = cur->next;
while (tmp != NULL && occur == 0) {
if (tmp->type == XML_COMMENT_NODE)
occur++;
if (tmp->type == XML_COMMENT_NODE)
occur++;
tmp = tmp->next;
}
if (occur != 0)
@ -8249,7 +8259,7 @@ xmlDOMWrapRemoveNode(xmlDOMWrapCtxtPtr ctxt, xmlDocPtr doc,
ns = ns->next;
} while (ns != NULL);
}
/* No break on purpose. */
/* Falls through. */
case XML_ATTRIBUTE_NODE:
if (node->ns != NULL) {
/*
@ -8840,7 +8850,7 @@ next_ns_decl:
}
if (! adoptns)
goto ns_end;
/* No break on purpose. */
/* Falls through. */
case XML_ATTRIBUTE_NODE:
/* No ns, no fun. */
if (cur->ns == NULL)
@ -9121,7 +9131,7 @@ xmlDOMWrapAdoptBranch(xmlDOMWrapCtxtPtr ctxt,
goto internal_error;
}
}
/* No break on purpose. */
/* Falls through. */
case XML_ATTRIBUTE_NODE:
/* No namespace, no fun. */
if (cur->ns == NULL)

View file

@ -327,7 +327,7 @@ trio_nan(TRIO_NOARGS)
if (result == 0.0) {
#if defined(TRIO_COMPILER_SUPPORTS_C99) && !defined(__clang__)
#if defined(TRIO_COMPILER_SUPPORTS_C99)
result = nan("");
#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);
if (bas->authority != NULL)
res->authority = xmlMemStrdup(bas->authority);
else if (bas->server != NULL) {
res->server = xmlMemStrdup(bas->server);
else if ((bas->server != NULL) || (bas->port == -1)) {
if (bas->server != NULL)
res->server = xmlMemStrdup(bas->server);
if (bas->user != NULL)
res->user = xmlMemStrdup(bas->user);
res->port = bas->port;
@ -2024,8 +2025,9 @@ xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
}
if (bas->authority != NULL)
res->authority = xmlMemStrdup(bas->authority);
else if (bas->server != NULL) {
res->server = xmlMemStrdup(bas->server);
else if ((bas->server != NULL) || (bas->port == -1)) {
if (bas->server != NULL)
res->server = xmlMemStrdup(bas->server);
if (bas->user != NULL)
res->user = xmlMemStrdup(bas->user);
res->port = bas->port;
@ -2163,7 +2165,6 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
xmlChar *val = NULL;
int ret;
int ix;
int pos = 0;
int nbslash = 0;
int len;
xmlURIPtr ref = NULL;
@ -2254,19 +2255,22 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
uptr = NULL;
len = 1; /* this is for a string terminator only */
} else {
/*
* Next we compare the two strings and find where they first differ
*/
if ((ref->path[pos] == '.') && (ref->path[pos+1] == '/'))
pos += 2;
xmlChar *rptr = (xmlChar *) ref->path;
int pos = 0;
/*
* Next we compare the two strings and find where they first differ
*/
if ((*rptr == '.') && (rptr[1] == '/'))
rptr += 2;
if ((*bptr == '.') && (bptr[1] == '/'))
bptr += 2;
else if ((*bptr == '/') && (ref->path[pos] != '/'))
else if ((*bptr == '/') && (*rptr != '/'))
bptr++;
while ((bptr[pos] == ref->path[pos]) && (bptr[pos] != 0))
while ((bptr[pos] == rptr[pos]) && (bptr[pos] != 0))
pos++;
if (bptr[pos] == ref->path[pos]) {
if (bptr[pos] == rptr[pos]) {
val = xmlStrdup(BAD_CAST "");
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
*/
ix = pos;
if ((ref->path[ix] == '/') && (ix > 0))
if ((rptr[ix] == '/') && (ix > 0))
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;
for (; ix > 0; ix--) {
if (ref->path[ix] == '/')
if (rptr[ix] == '/')
break;
}
if (ix == 0) {
uptr = (xmlChar *)ref->path;
uptr = (xmlChar *)rptr;
} else {
ix++;
uptr = (xmlChar *)&ref->path[ix];
uptr = (xmlChar *)&rptr[ix];
}
/*
* 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++) {
if (bptr[ix] == '/')
nbslash++;
@ -2390,8 +2394,7 @@ xmlCanonicPath(const xmlChar *path)
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
int len = 0;
int i = 0;
xmlChar *p = NULL;
char *p = NULL;
#endif
xmlURIPtr uri;
xmlChar *ret;
@ -2455,6 +2458,7 @@ xmlCanonicPath(const xmlChar *path)
xmlFreeURI(uri);
return escURI;
}
xmlFree(escURI);
}
}
@ -2472,7 +2476,7 @@ path_processing:
len = xmlStrlen(path);
if ((len > 2) && IS_WINDOWS_PATH(path)) {
/* make the scheme 'file' */
uri->scheme = xmlStrdup(BAD_CAST "file");
uri->scheme = (char *) xmlStrdup(BAD_CAST "file");
/* allocate space for leading '/' + path + string terminator */
uri->path = xmlMallocAtomic(len + 2);
if (uri->path == NULL) {
@ -2482,9 +2486,9 @@ path_processing:
/* Put in leading '/' plus path */
uri->path[0] = '/';
p = uri->path + 1;
strncpy(p, path, len + 1);
strncpy(p, (char *) path, len + 1);
} else {
uri->path = xmlStrdup(path);
uri->path = (char *) xmlStrdup(path);
if (uri->path == NULL) {
xmlFreeURI(uri);
return(NULL);

View file

@ -163,7 +163,7 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt,
__xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
XML_ERR_ERROR, NULL, 0,
(const char *) str1,
(const char *) str1,
(const char *) str2,
(const char *) str3, 0, 0, msg, str1, str2, str3);
}
#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,
XML_ERR_WARNING, NULL, 0,
(const char *) str1,
(const char *) str1,
(const char *) str2,
(const char *) str3, 0, 0, msg, str1, str2, str3);
}
@ -1172,29 +1172,33 @@ xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob)
xmlBufferWriteCHAR(buf, content->name);
break;
case XML_ELEMENT_CONTENT_SEQ:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ))
if ((content->c1 != NULL) &&
((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)))
xmlDumpElementContent(buf, content->c1, 1);
else
xmlDumpElementContent(buf, content->c1, 0);
xmlBufferWriteChar(buf, " , ");
if ((content->c2->type == XML_ELEMENT_CONTENT_OR) ||
((content->c2->type == XML_ELEMENT_CONTENT_SEQ) &&
(content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)))
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))))
xmlDumpElementContent(buf, content->c2, 1);
else
xmlDumpElementContent(buf, content->c2, 0);
break;
case XML_ELEMENT_CONTENT_OR:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ))
if ((content->c1 != NULL) &&
((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ)))
xmlDumpElementContent(buf, content->c1, 1);
else
xmlDumpElementContent(buf, content->c1, 0);
xmlBufferWriteChar(buf, " | ");
if ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) ||
((content->c2->type == XML_ELEMENT_CONTENT_OR) &&
(content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)))
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))))
xmlDumpElementContent(buf, content->c2, 1);
else
xmlDumpElementContent(buf, content->c2, 0);
@ -1262,22 +1266,23 @@ xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int
case XML_ELEMENT_CONTENT_PCDATA:
strcat(buf, "#PCDATA");
break;
case XML_ELEMENT_CONTENT_ELEMENT:
if (content->prefix != NULL) {
if (size - len < xmlStrlen(content->prefix) + 10) {
strcat(buf, " ...");
return;
}
strcat(buf, (char *) content->prefix);
strcat(buf, ":");
}
if (size - len < xmlStrlen(content->name) + 10) {
case XML_ELEMENT_CONTENT_ELEMENT: {
int qnameLen = xmlStrlen(content->name);
if (content->prefix != NULL)
qnameLen += xmlStrlen(content->prefix) + 1;
if (size - len < qnameLen + 10) {
strcat(buf, " ...");
return;
}
if (content->prefix != NULL) {
strcat(buf, (char *) content->prefix);
strcat(buf, ":");
}
if (content->name != NULL)
strcat(buf, (char *) content->name);
break;
}
case XML_ELEMENT_CONTENT_SEQ:
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
(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);
break;
}
if (size - strlen(buf) <= 2) return;
if (englob)
strcat(buf, ")");
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 */
if (attrDecl->atype == XML_ATTRIBUTE_ID) {
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)
ret = 0;
}
#endif
/* Validity Constraint: Notation Attributes */
if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) {
@ -5177,6 +5190,7 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) {
case XML_TEXT_NODE:
if (xmlIsBlankNode(cur))
break;
/* Falls through. */
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
strcat(buf, "CDATA");
@ -5725,7 +5739,7 @@ xmlValidatePushElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
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) {
elemDecl = state->elemDecl;
@ -5817,7 +5831,7 @@ xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) {
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) {
elemDecl = state->elemDecl;
@ -5891,7 +5905,7 @@ xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED,
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) {
elemDecl = state->elemDecl;

View file

@ -12,6 +12,7 @@
#include "libxml.h"
#include <string.h>
#include <stddef.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
@ -39,7 +40,8 @@
#include <lzma.h>
#endif
#if defined(WIN32) || defined(_WIN32)
#if defined(_WIN32) && !defined(__CYGWIN__)
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h>
#include <winnls.h>
#endif
@ -48,38 +50,14 @@
#include <winnls.h> /* for CP_UTF8 */
#endif
/* Figure a portable way to know if a file is a directory. */
#ifndef HAVE_STAT
# ifdef HAVE__STAT
/* MS C library seems to define stat and _stat. The definition
is identical. Still, mapping them to each other causes a warning. */
# ifndef _MSC_VER
# define stat(x,y) _stat(x,y)
# endif
# 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
#ifndef S_ISDIR
# ifdef _S_ISDIR
# define S_ISDIR(x) _S_ISDIR(x)
# elif defined(S_IFDIR)
# ifdef S_IFMT
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# elif defined(_S_IFMT)
# define S_ISDIR(m) (((m) & _S_IFMT) == S_IFDIR)
# endif
# endif
#endif
@ -657,99 +635,19 @@ xmlWrapGzOpenUtf8(const char *path, const char *mode)
*
*/
static int
xmlWrapStatUtf8(const char *path,struct stat *info)
{
#ifdef HAVE_STAT
xmlWrapStatUtf8(const char *path, struct _stat *info) {
int retval = -1;
wchar_t *wPath;
wPath = __xmlIOWin32UTF8ToWChar(path);
if (wPath)
{
retval = _wstat(wPath,info);
if (wPath) {
retval = _wstat(wPath, info);
xmlFree(wPath);
}
/* maybe path in native encoding */
if(retval < 0)
retval = stat(path,info);
retval = _stat(path, info);
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
@ -772,7 +670,11 @@ int
xmlCheckFilename (const char *path)
{
#ifdef HAVE_STAT
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
struct _stat stat_buffer;
#else
struct stat stat_buffer;
#endif
#endif
if (path == NULL)
return(0);
@ -787,7 +689,7 @@ xmlCheckFilename (const char *path)
(path[3] == '\\') )
return 1;
if (xmlWrapStat(path, &stat_buffer) == -1)
if (xmlWrapStatUtf8(path, &stat_buffer) == -1)
return 0;
#else
if (stat(path, &stat_buffer) == -1)
@ -827,7 +729,7 @@ static int
xmlFdRead (void * context, char * buffer, int len) {
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()");
return(ret);
}
@ -848,7 +750,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
int ret = 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()");
}
return(ret);
@ -866,7 +768,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
static int
xmlFdClose (void * context) {
int ret;
ret = close((int) (long) context);
ret = close((int) (ptrdiff_t) context);
if (ret < 0) xmlIOErr(0, "close()");
return(ret);
}
@ -927,11 +829,14 @@ xmlFileOpen_real (const char *filename) {
#endif
}
/* Do not check DDNAME on zOS ! */
#if !defined(__MVS__)
if (!xmlCheckFilename(path))
return(NULL);
#endif
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapOpen(path, 0);
fd = xmlWrapOpenUtf8(path, 0);
#else
fd = fopen(path, "r");
#endif /* WIN32 */
@ -1004,12 +909,14 @@ xmlFileOpenW (const char *filename) {
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapOpen(path, 1);
fd = xmlWrapOpenUtf8(path, 1);
#elif(__MVS__)
fd = fopen(path, "w");
#else
fd = fopen(path, "wb");
fd = fopen(path, "wb");
#endif /* WIN32 */
if (fd == NULL) xmlIOErr(0, path);
if (fd == NULL) xmlIOErr(0, path);
return((void *) fd);
}
#endif /* LIBXML_OUTPUT_ENABLED */
@ -1194,7 +1101,7 @@ xmlGzfileOpen_real (const char *filename) {
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, "rb");
fd = xmlWrapGzOpenUtf8(path, "rb");
#else
fd = gzopen(path, "rb");
#endif
@ -1271,7 +1178,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
return(NULL);
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = xmlWrapGzOpen(path, mode);
fd = xmlWrapGzOpenUtf8(path, mode);
#else
fd = gzopen(path, mode);
#endif
@ -1287,7 +1194,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
*
* 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
xmlGzfileRead (void * context, char * buffer, int len) {
@ -1675,7 +1582,7 @@ xmlZMemBuffExtend( xmlZMemBuffPtr buff, size_t ext_amt ) {
xmlStrPrintf(msg, 500,
"xmlZMemBuffExtend: %s %lu bytes.\n",
"Allocation failure extending output buffer to",
new_size );
(unsigned long) new_size );
xmlIOErr(XML_IO_WRITE, (const char *) msg);
}
@ -1877,7 +1784,7 @@ xmlIOHTTPOpen (const char *filename) {
*/
void *
xmlIOHTTPOpenW(const char *post_uri, int compression)
xmlIOHTTPOpenW(const char *post_uri, int compression ATTRIBUTE_UNUSED)
{
xmlIOHTTPWriteCtxtPtr ctxt = NULL;
@ -2319,10 +2226,6 @@ xmlRegisterDefaultInputCallbacks(void) {
if (xmlInputCallbackInitialized)
return;
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
xmlInitPlatformSpecificIo();
#endif
xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen,
xmlFileRead, xmlFileClose);
#ifdef HAVE_ZLIB_H
@ -2357,10 +2260,6 @@ xmlRegisterDefaultOutputCallbacks (void) {
if (xmlOutputCallbackInitialized)
return;
#if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
xmlInitPlatformSpecificIo();
#endif
xmlRegisterOutputCallbacks(xmlFileMatch, xmlFileOpenW,
xmlFileWrite, xmlFileClose);
@ -3004,7 +2903,7 @@ xmlParserInputBufferCreateFd(int fd, xmlCharEncoding enc) {
ret = xmlAllocParserInputBuffer(enc);
if (ret != NULL) {
ret->context = (void *) (long) fd;
ret->context = (void *) (ptrdiff_t) fd;
ret->readcallback = xmlFdRead;
ret->closecallback = xmlFdClose;
}
@ -3028,7 +2927,7 @@ xmlParserInputBufferCreateMem(const char *mem, int size, xmlCharEncoding enc) {
xmlParserInputBufferPtr ret;
int errcode;
if (size <= 0) return(NULL);
if (size < 0) return(NULL);
if (mem == NULL) return(NULL);
ret = xmlAllocParserInputBuffer(enc);
@ -3064,7 +2963,7 @@ xmlParserInputBufferCreateStatic(const char *mem, int size,
xmlCharEncoding enc) {
xmlParserInputBufferPtr ret;
if (size <= 0) return(NULL);
if (size < 0) return(NULL);
if (mem == NULL) return(NULL);
ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer));
@ -3110,7 +3009,7 @@ xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) {
ret = xmlAllocOutputBufferInternal(encoder);
if (ret != NULL) {
ret->context = (void *) (long) fd;
ret->context = (void *) (ptrdiff_t) fd;
ret->writecallback = xmlFdWrite;
ret->closecallback = NULL;
}
@ -3824,7 +3723,7 @@ xmlParserGetDirectory(const char *filename) {
if (filename == NULL) return(NULL);
#if defined(WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32) && !defined(__CYGWIN__)
# define IS_XMLPGD_SEP(ch) ((ch=='/')||(ch=='\\'))
#else
# 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) */
printf("\
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--shell : run a shell allowing interactive queries\n\
\t--create : create a new catalog\n\
@ -408,11 +409,18 @@ int main(int argc, char **argv) {
continue;
} else if (argv[i][0] == '-')
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]);
if ((ret < 0) && (create)) {
xmlCatalogAdd(BAD_CAST "catalog", BAD_CAST argv[i], NULL);
}
}
break;
}

View file

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

View file

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

View file

@ -8,6 +8,11 @@
* 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
#include "libxml.h"
@ -296,9 +301,10 @@ xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
#endif /* HAVE_SHLLOAD */
#endif /* ! HAVE_DLOPEN */
#ifdef _WIN32
#if defined(_WIN32) && !defined(__CYGWIN__)
//#include <windows.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/*
* xmlModulePlatformOpen:

View file

@ -3982,7 +3982,7 @@ xmlTextReaderPreserve(xmlTextReaderPtr reader) {
* pattern. The caller must also use xmlTextReaderCurrentDoc() to
* 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
xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern,

View file

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

View file

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

View file

@ -44,6 +44,12 @@
* but is done here due to performance. Move it to an other layer
* 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
#include "libxml.h"
@ -166,7 +172,7 @@ static const xmlChar *xmlNamespaceNs = (const xmlChar *)
/*
* 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))
@ -363,6 +369,7 @@ typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
struct _xmlSchemaAbstractCtxt {
int type; /* E.g. XML_SCHEMA_CTXT_VALIDATOR */
void *dummy; /* Fix alignment issues */
};
typedef struct _xmlSchemaBucket xmlSchemaBucket;
@ -473,6 +480,7 @@ typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
struct _xmlSchemaBasicItem {
xmlSchemaTypeType type;
void *dummy; /* Fix alignment issues */
};
/**
@ -1734,6 +1742,7 @@ xmlSchemaFormatItemForReport(xmlChar **buf,
*buf = xmlStrcat(*buf, BAD_CAST "'");
FREE_AND_NULL(str);
}
/* Falls through. */
default:
named = 0;
}
@ -15890,7 +15899,7 @@ xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
* STATUS: (seems) complete
*
* 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
xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
@ -16137,7 +16146,7 @@ xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
* (1.4.3.2.2.2) "Particle Valid (Extension)"
*
* 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
xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
@ -16394,7 +16403,7 @@ xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
* Validation Rule: Checking complex type subsumption
*
* 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
xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
@ -16584,7 +16593,7 @@ xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
* (3.4.6) Constraints on Complex Type Definition Schema Components
*
* 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
xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
@ -16614,7 +16623,7 @@ xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
* Complex Type Definition Representation OK (src-ct)
*
* 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
xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
@ -16783,7 +16792,7 @@ xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
* STATUS: complete
*
* 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
xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
@ -16813,7 +16822,7 @@ xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
* CLARIFY: (3.2.2)
*
* 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
xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
@ -16918,7 +16927,7 @@ xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
* STATUS: complete
*
* 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
xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
@ -16962,7 +16971,7 @@ xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
* STATUS: TODO
*
* 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
xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
@ -16988,7 +16997,7 @@ xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
* STATUS: complete
*
* 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
xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
@ -17038,7 +17047,7 @@ xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
* STATUS: TODO
*
* 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
xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
@ -17079,7 +17088,7 @@ xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
* STATUS: TODO: subst-groups
*
* 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
xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
@ -17134,7 +17143,7 @@ xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
* TODO: subst-groups
*
* 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
xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
@ -17764,7 +17773,7 @@ xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt,
return (0);
internal_error:
PERROR_INT("xmlSchemaDeriveAndValidateFacets",
"an error occured");
"an error occurred");
return (-1);
}
@ -21413,7 +21422,7 @@ exit_failure:
ctxt->ownsConstructor = 0;
}
PERROR_INT2("xmlSchemaParse",
"An internal error occured");
"An internal error occurred");
ctxt->schema = NULL;
return(NULL);
}
@ -22029,7 +22038,7 @@ xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef,
* Creates an augmented IDC definition for the imported schema.
*/
static void
xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt) {
xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt, xmlChar *name ATTRIBUTE_UNUSED) {
if (imported->schema->idcDef != NULL) {
xmlHashScan(imported->schema->idcDef ,
(xmlHashScanner) xmlSchemaAugmentIDC, vctxt);
@ -26094,7 +26103,7 @@ xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
/*
* 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,
&nbval, &nbneg, &values[0], &terminal);
@ -27150,7 +27159,7 @@ root_found:
}
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;
goto exit;
@ -27391,6 +27400,7 @@ xmlSchemaSAXHandleStartElementNs(void *ctx,
* attributes yet.
*/
if (nb_attributes != 0) {
int valueLen, k, l;
xmlChar *value;
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
* as &#38; instead of delivering the raw converted string. Changing the
* 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
* decoding some entity other than &#38; in this step because without
* unescaped ampersands there can be no other entities in the string.
* we are forced to work around it.
*/
value = xmlStringLenDecodeEntities(vctxt->parserCtxt, attributes[j+3],
attributes[j+4] - attributes[j+3], XML_SUBSTITUTE_REF, 0, 0, 0);
valueLen = attributes[j+4] - attributes[j+3];
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.
*/

View file

@ -7,6 +7,11 @@
* Daniel Veillard <veillard@redhat.com>
*/
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML
#include "libxml.h"
@ -5398,7 +5403,7 @@ xmlSchemaValidateFacetInternal(xmlSchemaFacetPtr facet,
if ((valType == XML_SCHEMAS_QNAME) ||
(valType == XML_SCHEMAS_NOTATION))
return (0);
/* No break on purpose. */
/* Falls through. */
case XML_SCHEMA_FACET_MAXLENGTH:
case XML_SCHEMA_FACET_MINLENGTH: {
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
* and NULL will be returned.
*
* Returns a new xmlChar *, the original @cur is reallocated if needed
* and should not be freed
* Returns a new xmlChar *, the original @cur is reallocated and should
* not be freed.
*/
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
* 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 *
xmlStrcat(xmlChar *cur, const xmlChar *add) {
@ -822,7 +823,7 @@ xmlCheckUTF8(const unsigned char *utf)
* @len: the number of characters in the array
*
* 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
* the first 'len' characters of ARRAY

View file

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

View file

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

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,11 @@
* daniel@veillard.com
*/
/* To avoid EBCDIC trouble when parsing on zOS */
#if defined(__MVS__)
#pragma convert("ISO8859-1")
#endif
#define IN_LIBXML
#include "libxml.h"
@ -99,6 +104,10 @@ xmlXPtrErr(xmlXPathParserContextPtr ctxt, int error,
msg, extra);
return;
}
/* cleanup current last error */
xmlResetError(&ctxt->context->lastError);
ctxt->context->lastError.domain = XML_FROM_XPOINTER;
ctxt->context->lastError.code = error;
ctxt->context->lastError.level = XML_ERR_ERROR;
@ -319,6 +328,45 @@ xmlXPtrRangesEqual(xmlXPathObjectPtr range1, xmlXPathObjectPtr range2) {
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:
* @start: the starting node
@ -344,17 +392,7 @@ xmlXPtrNewRange(xmlNodePtr start, int startindex,
if (endindex < 0)
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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;
ret = xmlXPtrNewRangeInternal(start, startindex, end, endindex);
xmlXPtrRangeCheckOrder(ret);
return(ret);
}
@ -381,17 +419,8 @@ xmlXPtrNewRangePoints(xmlXPathObjectPtr start, xmlXPathObjectPtr end) {
if (end->type != XPATH_POINT)
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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->user;
ret->index2 = end->index;
ret = xmlXPtrNewRangeInternal(start->user, start->index, end->user,
end->index);
xmlXPtrRangeCheckOrder(ret);
return(ret);
}
@ -416,17 +445,7 @@ xmlXPtrNewRangePointNode(xmlXPathObjectPtr start, xmlNodePtr end) {
if (start->type != XPATH_POINT)
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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;
ret = xmlXPtrNewRangeInternal(start->user, start->index, end, -1);
xmlXPtrRangeCheckOrder(ret);
return(ret);
}
@ -453,17 +472,7 @@ xmlXPtrNewRangeNodePoint(xmlNodePtr start, xmlXPathObjectPtr end) {
if (end->type != XPATH_POINT)
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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;
ret = xmlXPtrNewRangeInternal(start, -1, end->user, end->index);
xmlXPtrRangeCheckOrder(ret);
return(ret);
}
@ -486,17 +495,7 @@ xmlXPtrNewRangeNodes(xmlNodePtr start, xmlNodePtr end) {
if (end == NULL)
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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;
ret = xmlXPtrNewRangeInternal(start, -1, end, -1);
xmlXPtrRangeCheckOrder(ret);
return(ret);
}
@ -516,17 +515,7 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {
if (start == NULL)
return(NULL);
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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;
ret = xmlXPtrNewRangeInternal(start, -1, NULL, -1);
return(ret);
}
@ -541,6 +530,8 @@ xmlXPtrNewCollapsedRange(xmlNodePtr start) {
*/
xmlXPathObjectPtr
xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
xmlNodePtr endNode;
int endIndex;
xmlXPathObjectPtr ret;
if (start == NULL)
@ -549,47 +540,28 @@ xmlXPtrNewRangeNodeObject(xmlNodePtr start, xmlXPathObjectPtr end) {
return(NULL);
switch (end->type) {
case XPATH_POINT:
endNode = end->user;
endIndex = end->index;
break;
case XPATH_RANGE:
endNode = end->user2;
endIndex = end->index2;
break;
case XPATH_NODESET:
/*
* Empty set ...
*/
if (end->nodesetval->nodeNr <= 0)
if ((end->nodesetval == NULL) || (end->nodesetval->nodeNr <= 0))
return(NULL);
endNode = end->nodesetval->nodeTab[end->nodesetval->nodeNr - 1];
endIndex = -1;
break;
default:
/* TODO */
return(NULL);
}
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
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);
}
ret = xmlXPtrNewRangeInternal(start, -1, endNode, endIndex);
xmlXPtrRangeCheckOrder(ret);
return(ret);
}
@ -986,8 +958,10 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
if (name == NULL)
XP_ERROR(XPATH_EXPR_ERROR);
if (CUR != '(')
if (CUR != '(') {
xmlFree(name);
XP_ERROR(XPATH_EXPR_ERROR);
}
NEXT;
level = 1;
@ -996,6 +970,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
buffer = (xmlChar *) xmlMallocAtomic(len * sizeof (xmlChar));
if (buffer == NULL) {
xmlXPtrErrMemory("allocating buffer");
xmlFree(name);
return;
}
@ -1020,6 +995,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
*cur = 0;
if ((level != 0) && (CUR == 0)) {
xmlFree(name);
xmlFree(buffer);
XP_ERROR(XPTR_SYNTAX_ERROR);
}
@ -1052,6 +1028,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) {
if (name2 == NULL) {
CUR_PTR = left;
xmlFree(buffer);
xmlFree(name);
XP_ERROR(XPATH_EXPR_ERROR);
}
xmlXPtrEvalChildSeq(ctxt, name2);
@ -1332,8 +1309,6 @@ xmlXPtrNewContext(xmlDocPtr doc, xmlNodePtr here, xmlNodePtr origin) {
ret->here = here;
ret->origin = origin;
xmlXPathRegisterFunc(ret, (xmlChar *)"range-to",
xmlXPtrRangeToFunction);
xmlXPathRegisterFunc(ret, (xmlChar *)"range",
xmlXPtrRangeFunction);
xmlXPathRegisterFunc(ret, (xmlChar *)"range-inside",
@ -1400,7 +1375,7 @@ xmlXPtrEval(const xmlChar *str, xmlXPathContextPtr ctx) {
*/
xmlNodeSetPtr set;
set = tmp->nodesetval;
if ((set->nodeNr != 1) ||
if ((set == NULL) || (set->nodeNr != 1) ||
(set->nodeTab[0] != (xmlNodePtr) ctx->doc))
stack++;
} else
@ -1835,8 +1810,8 @@ xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs) {
case XPATH_RANGE: {
xmlNodePtr node = tmp->user;
if (node != NULL) {
if (node->type == XML_ATTRIBUTE_NODE) {
/* TODO: Namespace Nodes ??? */
if ((node->type == XML_ATTRIBUTE_NODE) ||
(node->type == XML_NAMESPACE_DECL)) {
xmlXPathFreeObject(obj);
xmlXPtrFreeLocationSet(newset);
XP_ERROR(XPTR_SYNTAX_ERROR);
@ -1931,8 +1906,8 @@ xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs) {
case XPATH_RANGE: {
xmlNodePtr node = tmp->user2;
if (node != NULL) {
if (node->type == XML_ATTRIBUTE_NODE) {
/* TODO: Namespace Nodes ??? */
if ((node->type == XML_ATTRIBUTE_NODE) ||
(node->type == XML_NAMESPACE_DECL)) {
xmlXPathFreeObject(obj);
xmlXPtrFreeLocationSet(newset);
XP_ERROR(XPTR_SYNTAX_ERROR);
@ -2073,9 +2048,11 @@ xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathFreeObject(set);
XP_ERROR(XPATH_MEMORY_ERROR);
}
for (i = 0;i < oldset->locNr;i++) {
xmlXPtrLocationSetAdd(newset,
xmlXPtrCoveringRange(ctxt, oldset->locTab[i]));
if (oldset != NULL) {
for (i = 0;i < oldset->locNr;i++) {
xmlXPtrLocationSetAdd(newset,
xmlXPtrCoveringRange(ctxt, oldset->locTab[i]));
}
}
/*
@ -2243,76 +2220,14 @@ xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs) {
* @nargs: the number of args
*
* 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
xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt, int nargs) {
xmlXPathObjectPtr range;
const xmlChar *cur;
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));
xmlXPtrRangeToFunction(xmlXPathParserContextPtr ctxt,
int nargs ATTRIBUTE_UNUSED) {
XP_ERROR(XPATH_EXPR_ERROR);
}
/**

View file

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