https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fc82f8e2e3cf01cf9c79d…
commit fc82f8e2e3cf01cf9c79d6feff823dba33094fbd
Author: Thomas Faber <thomas.faber(a)reactos.org>
AuthorDate: Sun Feb 4 17:15:47 2018 +0100
Commit: Thomas Faber <thomas.faber(a)reactos.org>
CommitDate: Mon Feb 5 18:55:48 2018 +0100
[LIBXML2] Update to version 2.9.7. CORE-14291
---
sdk/include/reactos/libs/libxml/HTMLparser.h | 4 +-
sdk/include/reactos/libs/libxml/nanoftp.h | 2 +-
sdk/include/reactos/libs/libxml/schemasInternals.h | 2 +-
sdk/include/reactos/libs/libxml/threads.h | 9 +-
sdk/include/reactos/libs/libxml/xmlreader.h | 2 +-
sdk/include/reactos/libs/libxml/xmlversion.h | 10 +-
sdk/lib/3rdparty/libxml2/ChangeLog | 18 +-
sdk/lib/3rdparty/libxml2/HTMLparser.c | 16 +-
sdk/lib/3rdparty/libxml2/SAX2.c | 14 +-
sdk/lib/3rdparty/libxml2/buf.c | 6 +-
sdk/lib/3rdparty/libxml2/c14n.c | 7 -
sdk/lib/3rdparty/libxml2/catalog.c | 1 +
sdk/lib/3rdparty/libxml2/config.h | 6 +-
sdk/lib/3rdparty/libxml2/debugXML.c | 2 +-
sdk/lib/3rdparty/libxml2/dict.c | 41 +-
sdk/lib/3rdparty/libxml2/elfgcchack.h | 2 +-
sdk/lib/3rdparty/libxml2/encoding.c | 590 ++++-----
sdk/lib/3rdparty/libxml2/entities.c | 7 +-
sdk/lib/3rdparty/libxml2/error.c | 4 +-
sdk/lib/3rdparty/libxml2/hash.c | 4 +-
sdk/lib/3rdparty/libxml2/include/win32config.h | 5 -
sdk/lib/3rdparty/libxml2/include/wsockcompat.h | 71 +-
sdk/lib/3rdparty/libxml2/libxml.h | 2 +-
sdk/lib/3rdparty/libxml2/list.c | 4 +-
sdk/lib/3rdparty/libxml2/nanoftp.c | 18 +-
sdk/lib/3rdparty/libxml2/nanohttp.c | 47 +-
sdk/lib/3rdparty/libxml2/parser.c | 1271 ++++++++------------
sdk/lib/3rdparty/libxml2/parserInternals.c | 30 +-
sdk/lib/3rdparty/libxml2/pattern.c | 1 +
sdk/lib/3rdparty/libxml2/relaxng.c | 17 +-
sdk/lib/3rdparty/libxml2/threads.c | 82 +-
sdk/lib/3rdparty/libxml2/timsort.h | 584 +++++----
sdk/lib/3rdparty/libxml2/tree.c | 28 +-
sdk/lib/3rdparty/libxml2/trionan.c | 2 +-
sdk/lib/3rdparty/libxml2/uri.c | 52 +-
sdk/lib/3rdparty/libxml2/valid.c | 62 +-
sdk/lib/3rdparty/libxml2/xmlIO.c | 185 +--
sdk/lib/3rdparty/libxml2/xmlcatalog.c | 12 +-
sdk/lib/3rdparty/libxml2/xmllint.c | 172 ++-
sdk/lib/3rdparty/libxml2/xmlmemory.c | 27 +-
sdk/lib/3rdparty/libxml2/xmlmodule.c | 10 +-
sdk/lib/3rdparty/libxml2/xmlreader.c | 2 +-
sdk/lib/3rdparty/libxml2/xmlregexp.c | 15 +-
sdk/lib/3rdparty/libxml2/xmlsave.c | 5 -
sdk/lib/3rdparty/libxml2/xmlschemas.c | 77 +-
sdk/lib/3rdparty/libxml2/xmlschemastypes.c | 7 +-
sdk/lib/3rdparty/libxml2/xmlstring.c | 9 +-
sdk/lib/3rdparty/libxml2/xmlunicode.c | 6 +-
sdk/lib/3rdparty/libxml2/xmlwriter.c | 1 +
sdk/lib/3rdparty/libxml2/xpath.c | 590 +++++----
sdk/lib/3rdparty/libxml2/xpointer.c | 261 ++--
sdk/lib/3rdparty/libxml2/xzlib.c | 4 +-
52 files changed, 1963 insertions(+), 2443 deletions(-)
diff --git a/sdk/include/reactos/libs/libxml/HTMLparser.h
b/sdk/include/reactos/libs/libxml/HTMLparser.h
index 551186cb0c..1d4fec2f73 100644
--- a/sdk/include/reactos/libs/libxml/HTMLparser.h
+++ b/sdk/include/reactos/libs/libxml/HTMLparser.h
@@ -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,
diff --git a/sdk/include/reactos/libs/libxml/nanoftp.h
b/sdk/include/reactos/libs/libxml/nanoftp.h
index abb4bf7142..7335faf107 100644
--- a/sdk/include/reactos/libs/libxml/nanoftp.h
+++ b/sdk/include/reactos/libs/libxml/nanoftp.h
@@ -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
/**
diff --git a/sdk/include/reactos/libs/libxml/schemasInternals.h
b/sdk/include/reactos/libs/libxml/schemasInternals.h
index c7cf55255a..6fb71139ce 100644
--- a/sdk/include/reactos/libs/libxml/schemasInternals.h
+++ b/sdk/include/reactos/libs/libxml/schemasInternals.h
@@ -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.
*
diff --git a/sdk/include/reactos/libs/libxml/threads.h
b/sdk/include/reactos/libs/libxml/threads.h
index d31f16acbd..9969ae7cfd 100644
--- a/sdk/include/reactos/libs/libxml/threads.h
+++ b/sdk/include/reactos/libs/libxml/threads.h
@@ -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
diff --git a/sdk/include/reactos/libs/libxml/xmlreader.h
b/sdk/include/reactos/libs/libxml/xmlreader.h
index 2c99e3a765..e8a8bcc9aa 100644
--- a/sdk/include/reactos/libs/libxml/xmlreader.h
+++ b/sdk/include/reactos/libs/libxml/xmlreader.h
@@ -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
*/
diff --git a/sdk/include/reactos/libs/libxml/xmlversion.h
b/sdk/include/reactos/libs/libxml/xmlversion.h
index 7f200055b2..90d61f507a 100644
--- a/sdk/include/reactos/libs/libxml/xmlversion.h
+++ b/sdk/include/reactos/libs/libxml/xmlversion.h
@@ -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
diff --git a/sdk/lib/3rdparty/libxml2/ChangeLog b/sdk/lib/3rdparty/libxml2/ChangeLog
index ef6cb8e427..896fbbb653 100644
--- a/sdk/lib/3rdparty/libxml2/ChangeLog
+++ b/sdk/lib/3rdparty/libxml2/ChangeLog
@@ -1929,7 +1929,7 @@ Mon Jun 12 12:54:25 CEST 2006 Kasimier Buchcik
<libxml2-cvs(a)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(a)cazic.net>
@@ -2305,7 +2305,7 @@ Mon Mar 6 14:21:08 CET 2006 Kasimier Buchcik
<libxml2-cvs(a)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(a)ctindustries.net>
@@ -3951,7 +3951,7 @@ Thu Jun 30 15:01:52 CEST 2005 Daniel Veillard
<daniel(a)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(a)veillard.com>
@@ -4356,7 +4356,7 @@ Fri Apr 8 21:58:04 CEST 2005 Kasimier Buchcik
<libxml2-cvs(a)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(a)cazic.net>
Mon Mar 21 21:09:07 CET 2005 Kasimier Buchcik <libxml2-cvs(a)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(a)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(a)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(a)aleksey.com>
@@ -15356,7 +15356,7 @@ Sat Oct 6 15:27:12 CEST 2001 Daniel Veillard
<daniel(a)veillard.com>
Sat Oct 6 15:07:14 CEST 2001 Daniel Veillard <daniel(a)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(a)veillard.com>
@@ -15970,7 +15970,7 @@ Tue Jul 10 17:47:09 CEST 2001 Daniel Veillard
<Daniel.Veillard(a)imag.fr>
Mon Jul 9 22:06:53 CEST 2001 Daniel Veillard <Daniel.Veillard(a)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(a)imag.fr>
diff --git a/sdk/lib/3rdparty/libxml2/HTMLparser.c
b/sdk/lib/3rdparty/libxml2/HTMLparser.c
index d1395fa507..e4f816e5e7 100644
--- a/sdk/lib/3rdparty/libxml2/HTMLparser.c
+++ b/sdk/lib/3rdparty/libxml2/HTMLparser.c
@@ -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));
}
diff --git a/sdk/lib/3rdparty/libxml2/SAX2.c b/sdk/lib/3rdparty/libxml2/SAX2.c
index 5cbb700af5..0f261b7b36 100644
--- a/sdk/lib/3rdparty/libxml2/SAX2.c
+++ b/sdk/lib/3rdparty/libxml2/SAX2.c
@@ -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);
}
}
diff --git a/sdk/lib/3rdparty/libxml2/buf.c b/sdk/lib/3rdparty/libxml2/buf.c
index 07922ff693..21cb9d8047 100644
--- a/sdk/lib/3rdparty/libxml2/buf.c
+++ b/sdk/lib/3rdparty/libxml2/buf.c
@@ -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
diff --git a/sdk/lib/3rdparty/libxml2/c14n.c b/sdk/lib/3rdparty/libxml2/c14n.c
index ca77f922a0..be687ea398 100644
--- a/sdk/lib/3rdparty/libxml2/c14n.c
+++ b/sdk/lib/3rdparty/libxml2/c14n.c
@@ -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;
diff --git a/sdk/lib/3rdparty/libxml2/catalog.c b/sdk/lib/3rdparty/libxml2/catalog.c
index 6dfdfbb8ca..f6186a1c84 100644
--- a/sdk/lib/3rdparty/libxml2/catalog.c
+++ b/sdk/lib/3rdparty/libxml2/catalog.c
@@ -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:
diff --git a/sdk/lib/3rdparty/libxml2/config.h b/sdk/lib/3rdparty/libxml2/config.h
index 9818139138..9e23531e20 100644
--- a/sdk/lib/3rdparty/libxml2/config.h
+++ b/sdk/lib/3rdparty/libxml2/config.h
@@ -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 */
diff --git a/sdk/lib/3rdparty/libxml2/debugXML.c b/sdk/lib/3rdparty/libxml2/debugXML.c
index a1b550ac53..a8ec8a4611 100644
--- a/sdk/lib/3rdparty/libxml2/debugXML.c
+++ b/sdk/lib/3rdparty/libxml2/debugXML.c
@@ -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
diff --git a/sdk/lib/3rdparty/libxml2/dict.c b/sdk/lib/3rdparty/libxml2/dict.c
index c0585fe239..0ef3718da2 100644
--- a/sdk/lib/3rdparty/libxml2/dict.c
+++ b/sdk/lib/3rdparty/libxml2/dict.c
@@ -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;
}
diff --git a/sdk/lib/3rdparty/libxml2/elfgcchack.h
b/sdk/lib/3rdparty/libxml2/elfgcchack.h
index 8c52884a37..5ac93bfb9f 100644
--- a/sdk/lib/3rdparty/libxml2/elfgcchack.h
+++ b/sdk/lib/3rdparty/libxml2/elfgcchack.h
@@ -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"
diff --git a/sdk/lib/3rdparty/libxml2/encoding.c b/sdk/lib/3rdparty/libxml2/encoding.c
index e49c7f898f..cd019c5191 100644
--- a/sdk/lib/3rdparty/libxml2/encoding.c
+++ b/sdk/lib/3rdparty/libxml2/encoding.c
@@ -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;
- }
- }
-#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;
+ /* Can be a limitation of iconv or uconv */
+ goto retry;
}
- }
-#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);
-
- goto retry;
- } else {
+ /*
+ * 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);
+
+ 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);
-
- goto retry;
- } else {
+ /*
+ * 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);
+
+ 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);
diff --git a/sdk/lib/3rdparty/libxml2/entities.c b/sdk/lib/3rdparty/libxml2/entities.c
index c40e2cf98c..c819337638 100644
--- a/sdk/lib/3rdparty/libxml2/entities.c
+++ b/sdk/lib/3rdparty/libxml2/entities.c
@@ -6,6 +6,11 @@
* daniel(a)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(a)sseusa.com> provided the patch
+ * Bjørn Reese <br(a)sseusa.com> provided the patch
xmlChar xc;
xc = (*cur & 0x3F) << 6;
if (cur[1] != 0) {
diff --git a/sdk/lib/3rdparty/libxml2/error.c b/sdk/lib/3rdparty/libxml2/error.c
index 9606f1357e..50e9e6f860 100644
--- a/sdk/lib/3rdparty/libxml2/error.c
+++ b/sdk/lib/3rdparty/libxml2/error.c
@@ -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)
diff --git a/sdk/lib/3rdparty/libxml2/hash.c b/sdk/lib/3rdparty/libxml2/hash.c
index f9a2017224..5dcaeb4021 100644
--- a/sdk/lib/3rdparty/libxml2/hash.c
+++ b/sdk/lib/3rdparty/libxml2/hash.c
@@ -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) {
diff --git a/sdk/lib/3rdparty/libxml2/include/win32config.h
b/sdk/lib/3rdparty/libxml2/include/win32config.h
index 40cf7df804..85967551c8 100644
--- a/sdk/lib/3rdparty/libxml2/include/win32config.h
+++ b/sdk/lib/3rdparty/libxml2/include/win32config.h
@@ -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
*/
diff --git a/sdk/lib/3rdparty/libxml2/include/wsockcompat.h
b/sdk/lib/3rdparty/libxml2/include/wsockcompat.h
index fbe8d0672a..0484ee36c6 100644
--- a/sdk/lib/3rdparty/libxml2/include/wsockcompat.h
+++ b/sdk/lib/3rdparty/libxml2/include/wsockcompat.h
@@ -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
-#endif
+#undef XML_SOCKLEN_T
+#define XML_SOCKLEN_T int
-#if !defined SOCKLEN_T
-#define SOCKLEN_T int
+#ifndef ECONNRESET
+#define ECONNRESET WSAECONNRESET
+#endif
+#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__ */
diff --git a/sdk/lib/3rdparty/libxml2/libxml.h b/sdk/lib/3rdparty/libxml2/libxml.h
index c3e2748d60..4fe56d21eb 100644
--- a/sdk/lib/3rdparty/libxml2/libxml.h
+++ b/sdk/lib/3rdparty/libxml2/libxml.h
@@ -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
diff --git a/sdk/lib/3rdparty/libxml2/list.c b/sdk/lib/3rdparty/libxml2/list.c
index d33d92818a..caa8333138 100644
--- a/sdk/lib/3rdparty/libxml2/list.c
+++ b/sdk/lib/3rdparty/libxml2/list.c
@@ -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)
diff --git a/sdk/lib/3rdparty/libxml2/nanoftp.c b/sdk/lib/3rdparty/libxml2/nanoftp.c
index 2135ab9b08..54fa026d1b 100644
--- a/sdk/lib/3rdparty/libxml2/nanoftp.c
+++ b/sdk/lib/3rdparty/libxml2/nanoftp.c
@@ -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:
diff --git a/sdk/lib/3rdparty/libxml2/nanohttp.c b/sdk/lib/3rdparty/libxml2/nanohttp.c
index 4593eb352f..9cd2292fdc 100644
--- a/sdk/lib/3rdparty/libxml2/nanohttp.c
+++ b/sdk/lib/3rdparty/libxml2/nanohttp.c
@@ -11,7 +11,6 @@
* daniel(a)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)
diff --git a/sdk/lib/3rdparty/libxml2/parser.c b/sdk/lib/3rdparty/libxml2/parser.c
index 53a6b7f0c9..1c5e036ea2 100644
--- a/sdk/lib/3rdparty/libxml2/parser.c
+++ b/sdk/lib/3rdparty/libxml2/parser.c
@@ -30,10 +30,15 @@
* daniel(a)veillard.com
*/
+/* To avoid EBCDIC trouble when parsing on zOS */
+#if defined(__MVS__)
+#pragma convert("ISO8859-1")
+#endif
+
#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 '/'
@@ -43,6 +48,7 @@
#include <limits.h>
#include <string.h>
#include <stdarg.h>
+#include <stddef.h>
#include <libxml/xmlmemory.h>
#include <libxml/threads.h>
#include <libxml/globals.h>
@@ -1087,7 +1093,12 @@ typedef xmlDefAttrs *xmlDefAttrsPtr;
struct _xmlDefAttrs {
int nbAttrs; /* number of defaulted attributes on that element */
int maxAttrs; /* the size of the array */
- const xmlChar *values[5]; /* array of localname/prefix/values/external */
+#if __STDC_VERSION__ >= 199901L
+ /* Using a C99 flexible array member avoids UBSan errors. */
+ const xmlChar *values[]; /* array of localname/prefix/values/external */
+#else
+ const xmlChar *values[5];
+#endif
};
/**
@@ -1324,7 +1335,7 @@ xmlAddSpecialAttr(xmlParserCtxtPtr ctxt,
return;
xmlHashAddEntry2(ctxt->attsSpecial, fullname, fullattr,
- (void *) (long) type);
+ (void *) (ptrdiff_t) type);
return;
mem_error:
@@ -1343,7 +1354,7 @@ xmlCleanSpecialAttrCallback(void *payload, void *data,
const xmlChar *unused ATTRIBUTE_UNUSED) {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) data;
- if (((long) payload) == XML_ATTRIBUTE_CDATA) {
+ if (((ptrdiff_t) payload) == XML_ATTRIBUTE_CDATA) {
xmlHashRemoveEntry2(ctxt->attsSpecial, fullname, fullattr, NULL);
}
}
@@ -1855,7 +1866,7 @@ nameNsPush(xmlParserCtxtPtr ctxt, const xmlChar * value,
ctxt->name = value;
ctxt->pushTab[ctxt->nameNr * 3] = (void *) prefix;
ctxt->pushTab[ctxt->nameNr * 3 + 1] = (void *) URI;
- ctxt->pushTab[ctxt->nameNr * 3 + 2] = (void *) (long) nsNr;
+ ctxt->pushTab[ctxt->nameNr * 3 + 2] = (void *) (ptrdiff_t) nsNr;
return (ctxt->nameNr++);
mem_error:
xmlErrMemory(ctxt, NULL);
@@ -2037,10 +2048,8 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
#define SKIP(val) do { \
ctxt->nbChars += (val),ctxt->input->cur +=
(val),ctxt->input->col+=(val); \
- if (*ctxt->input->cur == '%') 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); \
} while (0)
#define SKIPL(val) do { \
@@ -2052,10 +2061,8 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
ctxt->nbChars++; \
ctxt->input->cur++; \
} \
- if (*ctxt->input->cur == '%') 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); \
} while (0)
#define SHRINK if ((ctxt->progressive == 0) && \
@@ -2065,10 +2072,9 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
static void xmlSHRINK (xmlParserCtxtPtr ctxt) {
xmlParserInputShrink(ctxt->input);
- if ((*ctxt->input->cur == 0) &&
- (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
- xmlPopInput(ctxt);
- }
+ if (*ctxt->input->cur == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
+}
#define GROW if ((ctxt->progressive == 0) && \
(ctxt->input->end - ctxt->input->cur < INPUT_CHUNK)) \
@@ -2093,9 +2099,8 @@ static void xmlGROW (xmlParserCtxtPtr ctxt) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "cur index out of bound");
return;
}
- if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0)
&&
- (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
- xmlPopInput(ctxt);
+ if ((ctxt->input->cur != NULL) && (*ctxt->input->cur == 0))
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
}
#define SKIP_BLANKS xmlSkipBlankChars(ctxt)
@@ -2115,7 +2120,6 @@ static void xmlGROW (xmlParserCtxtPtr ctxt) {
ctxt->input->line++; ctxt->input->col = 1; \
} else ctxt->input->col++; \
ctxt->input->cur += l; \
- if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
} while (0)
#define CUR_CHAR(l) xmlCurrentChar(ctxt, &l)
@@ -2165,26 +2169,35 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
}
ctxt->input->cur = cur;
} else {
- int cur;
- do {
- cur = CUR;
- while ((IS_BLANK_CH(cur) && /* CHECKED tstblanks.xml */
- (ctxt->instate != XML_PARSER_EOF))) {
+ int expandPE = ((ctxt->external != 0) || (ctxt->inputNr != 1));
+
+ while (1) {
+ if (IS_BLANK_CH(CUR)) { /* CHECKED tstblanks.xml */
NEXT;
- cur = CUR;
- res++;
- }
- while ((cur == 0) && (ctxt->inputNr > 1) &&
- (ctxt->instate != XML_PARSER_COMMENT)) {
- xmlPopInput(ctxt);
- cur = CUR;
- }
- /*
- * Need to handle support of entities branching here
- */
- if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt);
- } while ((IS_BLANK(cur)) && /* CHECKED tstblanks.xml */
- (ctxt->instate != XML_PARSER_EOF));
+ } else if (CUR == '%') {
+ /*
+ * Need to handle support of entities branching here
+ */
+ if ((expandPE == 0) || (IS_BLANK_CH(NXT(1))) || (NXT(1) == 0))
+ break;
+ xmlParsePEReference(ctxt);
+ } else if (CUR == 0) {
+ if (ctxt->inputNr <= 1)
+ break;
+ xmlPopInput(ctxt);
+ } else {
+ break;
+ }
+
+ /*
+ * Also increase the counter when entering or exiting a PERef.
+ * The spec says: "When a parameter-entity reference is recognized
+ * in the DTD and included, its replacement text MUST be enlarged
+ * by the attachment of one leading and one following space (#x20)
+ * character."
+ */
+ res++;
+ }
}
return(res);
}
@@ -2210,10 +2223,13 @@ xmlPopInput(xmlParserCtxtPtr ctxt) {
if (xmlParserDebugEntities)
xmlGenericError(xmlGenericErrorContext,
"Popping input %d\n", ctxt->inputNr);
+ if ((ctxt->inputNr > 1) && (ctxt->inSubset == 0) &&
+ (ctxt->instate != XML_PARSER_EOF))
+ xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
+ "Unfinished entity outside the DTD");
xmlFreeInputStream(inputPop(ctxt));
- if ((*ctxt->input->cur == 0) &&
- (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0))
- return(xmlPopInput(ctxt));
+ if (*ctxt->input->cur == 0)
+ xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
return(CUR);
}
@@ -2239,6 +2255,13 @@ xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) {
xmlGenericError(xmlGenericErrorContext,
"Pushing input %d : %.30s\n", ctxt->inputNr+1, input->cur);
}
+ if (((ctxt->inputNr > 40) && ((ctxt->options & XML_PARSE_HUGE)
== 0)) ||
+ (ctxt->inputNr > 1024)) {
+ xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
+ while (ctxt->inputNr > 1)
+ xmlFreeInputStream(inputPop(ctxt));
+ return(-1);
+ }
ret = inputPush(ctxt, input);
if (ctxt->instate == XML_PARSER_EOF)
return(-1);
@@ -2443,57 +2466,6 @@ xmlParseStringCharRef(xmlParserCtxtPtr ctxt, const xmlChar **str)
{
return(0);
}
-/**
- * xmlNewBlanksWrapperInputStream:
- * @ctxt: an XML parser context
- * @entity: an Entity pointer
- *
- * Create a new input stream for wrapping
- * blanks around a PEReference
- *
- * Returns the new input stream or NULL
- */
-
-static void deallocblankswrapper (xmlChar *str) {xmlFree(str);}
-
-static xmlParserInputPtr
-xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
- xmlParserInputPtr input;
- xmlChar *buffer;
- size_t length;
- if (entity == NULL) {
- xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
- "xmlNewBlanksWrapperInputStream entity\n");
- return(NULL);
- }
- if (xmlParserDebugEntities)
- xmlGenericError(xmlGenericErrorContext,
- "new blanks wrapper for entity: %s\n", entity->name);
- input = xmlNewInputStream(ctxt);
- if (input == NULL) {
- return(NULL);
- }
- length = xmlStrlen(entity->name) + 5;
- buffer = xmlMallocAtomic(length);
- if (buffer == NULL) {
- xmlErrMemory(ctxt, NULL);
- xmlFree(input);
- return(NULL);
- }
- buffer [0] = ' ';
- buffer [1] = '%';
- buffer [length-3] = ';';
- buffer [length-2] = ' ';
- buffer [length-1] = 0;
- memcpy(buffer + 2, entity->name, length - 5);
- input->free = deallocblankswrapper;
- input->base = buffer;
- input->cur = buffer;
- input->length = length;
- input->end = &buffer[length];
- return(input);
-}
-
/**
* xmlParserHandlePEReference:
* @ctxt: the parser context
@@ -2528,11 +2500,6 @@ xmlNewBlanksWrapperInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr
entity) {
*/
void
xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
- const xmlChar *name;
- xmlEntityPtr entity = NULL;
- xmlParserInputPtr input;
-
- if (RAW != '%') return;
switch(ctxt->instate) {
case XML_PARSER_CDATA_SECTION:
return;
@@ -2587,128 +2554,7 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
return;
}
- NEXT;
- name = xmlParseName(ctxt);
- if (xmlParserDebugEntities)
- xmlGenericError(xmlGenericErrorContext,
- "PEReference: %s\n", name);
- if (name == NULL) {
- xmlFatalErr(ctxt, XML_ERR_PEREF_NO_NAME, NULL);
- } else {
- if (RAW == ';') {
- NEXT;
- if ((ctxt->sax != NULL) && (ctxt->sax->getParameterEntity !=
NULL))
- entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
- if (ctxt->instate == XML_PARSER_EOF)
- return;
- if (entity == NULL) {
-
- /*
- * [ WFC: Entity Declared ]
- * In a document without any DTD, a document with only an
- * internal DTD subset which contains no parameter entity
- * references, or a document with "standalone='yes'", ...
- * ... The declaration of a parameter entity must precede
- * any reference to it...
- */
- if ((ctxt->standalone == 1) ||
- ((ctxt->hasExternalSubset == 0) &&
- (ctxt->hasPErefs == 0))) {
- xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
- "PEReference: %%%s; not found\n", name);
- } else {
- /*
- * [ VC: Entity Declared ]
- * In a document with an external subset or external
- * parameter entities with "standalone='no'", ...
- * ... The declaration of a parameter entity must precede
- * any reference to it...
- */
- if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) {
- xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
- "PEReference: %%%s; not found\n",
- name, NULL);
- } else
- xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
- "PEReference: %%%s; not found\n",
- name, NULL);
- ctxt->valid = 0;
- }
- xmlParserEntityCheck(ctxt, 0, NULL, 0);
- } else if (ctxt->input->free != deallocblankswrapper) {
- input = xmlNewBlanksWrapperInputStream(ctxt, entity);
- if (xmlPushInput(ctxt, input) < 0)
- return;
- } else {
- if ((entity->etype == XML_INTERNAL_PARAMETER_ENTITY) ||
- (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY)) {
- xmlChar start[4];
- xmlCharEncoding enc;
-
- /*
- * Note: external parameter entities will not be loaded, it
- * is not required for a non-validating parser, unless the
- * option of validating, or substituting entities were
- * given. Doing so is far more secure as the parser will
- * only process data coming from the document entity by
- * default.
- */
- if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
- ((ctxt->options & XML_PARSE_NOENT) == 0) &&
- ((ctxt->options & XML_PARSE_DTDVALID) == 0) &&
- ((ctxt->options & XML_PARSE_DTDLOAD) == 0) &&
- ((ctxt->options & XML_PARSE_DTDATTR) == 0) &&
- (ctxt->replaceEntities == 0) &&
- (ctxt->validate == 0))
- return;
-
- /*
- * handle the extra spaces added before and after
- * c.f.
http://www.w3.org/TR/REC-xml#as-PE
- * this is done independently.
- */
- input = xmlNewEntityInputStream(ctxt, entity);
- if (xmlPushInput(ctxt, input) < 0)
- return;
-
- /*
- * Get the 4 first bytes and decode the charset
- * if enc != XML_CHAR_ENCODING_NONE
- * plug some encoding conversion routines.
- * Note that, since we may have some non-UTF8
- * encoding (like UTF16, bug 135229), the 'length'
- * is not known, but we can calculate based upon
- * the amount of data in the buffer.
- */
- GROW
- if (ctxt->instate == XML_PARSER_EOF)
- return;
- if ((ctxt->input->end - ctxt->input->cur)>=4) {
- start[0] = RAW;
- start[1] = NXT(1);
- start[2] = NXT(2);
- start[3] = NXT(3);
- enc = xmlDetectCharEncoding(start, 4);
- if (enc != XML_CHAR_ENCODING_NONE) {
- xmlSwitchEncoding(ctxt, enc);
- }
- }
-
- if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
- (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l' ))
&&
- (IS_BLANK_CH(NXT(5)))) {
- xmlParseTextDecl(ctxt);
- }
- } else {
- xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_PARAMETER,
- "PEReference: %s is not a parameter entity\n",
- name);
- }
- }
- } else {
- xmlFatalErr(ctxt, XML_ERR_PEREF_SEMICOL_MISSING, NULL);
- }
- }
+ xmlParsePEReference(ctxt);
}
/*
@@ -2790,9 +2636,9 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar
*str, int len,
if (c == 0) break;
if ((c == '&') && (str[1] == '#')) {
int val = xmlParseStringCharRef(ctxt, &str);
- if (val != 0) {
- COPY_BUF(0,buffer,nbchars,val);
- }
+ if (val == 0)
+ goto int_error;
+ COPY_BUF(0,buffer,nbchars,val);
if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
}
@@ -2802,9 +2648,6 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar
*str, int len,
"String decoding Entity Reference: %.30s\n",
str);
ent = xmlParseStringEntityRef(ctxt, &str);
- if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||
- (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
- goto int_error;
xmlParserEntityCheck(ctxt, 0, ent, 0);
if (ent != NULL)
ctxt->nbentities += ent->checked / 2;
@@ -2818,30 +2661,27 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar
*str, int len,
} else {
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
"predefined entity has no content\n");
+ goto int_error;
}
} else if ((ent != NULL) && (ent->content != NULL)) {
ctxt->depth++;
rep = xmlStringDecodeEntities(ctxt, ent->content, what,
0, 0, 0);
ctxt->depth--;
-
- if ((ctxt->lastError.code == XML_ERR_ENTITY_LOOP) ||
- (ctxt->lastError.code == XML_ERR_INTERNAL_ERROR))
- goto int_error;
-
- if (rep != NULL) {
- current = rep;
- while (*current != 0) { /* non input consuming loop */
- buffer[nbchars++] = *current++;
- if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
- if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
- goto int_error;
- growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
- }
- }
- xmlFree(rep);
- rep = NULL;
- }
+ if (rep == NULL)
+ goto int_error;
+
+ current = rep;
+ while (*current != 0) { /* non input consuming loop */
+ buffer[nbchars++] = *current++;
+ if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
+ if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
+ goto int_error;
+ growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
+ }
+ }
+ xmlFree(rep);
+ rep = NULL;
} else if (ent != NULL) {
int i = xmlStrlen(ent->name);
const xmlChar *cur = ent->name;
@@ -2859,8 +2699,6 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar
*str, int len,
xmlGenericError(xmlGenericErrorContext,
"String decoding PE Reference: %.30s\n", str);
ent = xmlParseStringPEReference(ctxt, &str);
- if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
- goto int_error;
xmlParserEntityCheck(ctxt, 0, ent, 0);
if (ent != NULL)
ctxt->nbentities += ent->checked / 2;
@@ -2886,19 +2724,19 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar
*str, int len,
rep = xmlStringDecodeEntities(ctxt, ent->content, what,
0, 0, 0);
ctxt->depth--;
- if (rep != NULL) {
- current = rep;
- while (*current != 0) { /* non input consuming loop */
- buffer[nbchars++] = *current++;
- if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
- if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
- goto int_error;
- growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
- }
- }
- xmlFree(rep);
- rep = NULL;
- }
+ if (rep == NULL)
+ goto int_error;
+ current = rep;
+ while (*current != 0) { /* non input consuming loop */
+ buffer[nbchars++] = *current++;
+ if (nbchars + XML_PARSER_BUFFER_SIZE > buffer_size) {
+ if (xmlParserEntityCheck(ctxt, nbchars, ent, 0))
+ goto int_error;
+ growBuffer(buffer, XML_PARSER_BUFFER_SIZE);
+ }
+ }
+ xmlFree(rep);
+ rep = NULL;
}
} else {
COPY_BUF(l,buffer,nbchars,c);
@@ -3406,13 +3244,6 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
len += l;
NEXTL(l);
c = CUR_CHAR(l);
- if (c == 0) {
- count = 0;
- GROW;
- if (ctxt->instate == XML_PARSER_EOF)
- return(NULL);
- c = CUR_CHAR(l);
- }
}
}
if ((len > XML_MAX_NAME_LENGTH) &&
@@ -3420,6 +3251,16 @@ xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "Name");
return(NULL);
}
+ if (ctxt->input->cur - ctxt->input->base < len) {
+ /*
+ * There were a couple of bugs where PERefs lead to to a change
+ * of the buffer. Check the buffer size to avoid passing an invalid
+ * pointer to xmlDictLookup.
+ */
+ xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
+ "unexpected change of input buffer");
+ return (NULL);
+ }
if ((*ctxt->input->cur == '\n') && (ctxt->input->cur[-1]
== '\r'))
return(xmlDictLookup(ctxt->dict, ctxt->input->cur - (len + 1), len));
return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
@@ -3892,10 +3733,8 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
ctxt->instate = XML_PARSER_ENTITY_VALUE;
input = ctxt->input;
GROW;
- if (ctxt->instate == XML_PARSER_EOF) {
- xmlFree(buf);
- return(NULL);
- }
+ if (ctxt->instate == XML_PARSER_EOF)
+ goto error;
NEXT;
c = CUR_CHAR(l);
/*
@@ -3916,18 +3755,12 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
if (tmp == NULL) {
xmlErrMemory(ctxt, NULL);
- xmlFree(buf);
- return(NULL);
+ goto error;
}
buf = tmp;
}
COPY_BUF(l,buf,len,c);
NEXTL(l);
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1)) /* non input consuming */
- xmlPopInput(ctxt);
GROW;
c = CUR_CHAR(l);
@@ -3937,10 +3770,13 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
}
}
buf[len] = 0;
- if (ctxt->instate == XML_PARSER_EOF) {
- xmlFree(buf);
- return(NULL);
+ if (ctxt->instate == XML_PARSER_EOF)
+ goto error;
+ if (c != stop) {
+ xmlFatalErr(ctxt, XML_ERR_ENTITY_NOT_FINISHED, NULL);
+ goto error;
}
+ NEXT;
/*
* Raise problem w.r.t. '&' and '%' being used in non-entities
@@ -3952,20 +3788,25 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
if ((*cur == '%') || ((*cur == '&') && (cur[1] !=
'#'))) {
xmlChar *name;
xmlChar tmp = *cur;
+ int nameOk = 0;
cur++;
name = xmlParseStringName(ctxt, &cur);
- if ((name == NULL) || (*cur != ';')) {
+ if (name != NULL) {
+ nameOk = 1;
+ xmlFree(name);
+ }
+ if ((nameOk == 0) || (*cur != ';')) {
xmlFatalErrMsgInt(ctxt, XML_ERR_ENTITY_CHAR_ERROR,
"EntityValue: '%c' forbidden except for entities references\n",
tmp);
+ goto error;
}
if ((tmp == '%') && (ctxt->inSubset == 1) &&
(ctxt->inputNr == 1)) {
xmlFatalErr(ctxt, XML_ERR_ENTITY_PE_INTERNAL, NULL);
+ goto error;
}
- if (name != NULL)
- xmlFree(name);
if (*cur == 0)
break;
}
@@ -3974,28 +3815,24 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
/*
* Then PEReference entities are substituted.
+ *
+ * NOTE: 4.4.7 Bypassed
+ * When a general entity reference appears in the EntityValue in
+ * an entity declaration, it is bypassed and left as is.
+ * so XML_SUBSTITUTE_REF is not set here.
*/
- if (c != stop) {
- xmlFatalErr(ctxt, XML_ERR_ENTITY_NOT_FINISHED, NULL);
- xmlFree(buf);
- } else {
- NEXT;
- /*
- * NOTE: 4.4.7 Bypassed
- * When a general entity reference appears in the EntityValue in
- * an entity declaration, it is bypassed and left as is.
- * so XML_SUBSTITUTE_REF is not set here.
- */
- ++ctxt->depth;
- ret = xmlStringDecodeEntities(ctxt, buf, XML_SUBSTITUTE_PEREF,
- 0, 0, 0);
- --ctxt->depth;
- if (orig != NULL)
- *orig = buf;
- else
- xmlFree(buf);
+ ++ctxt->depth;
+ ret = xmlStringDecodeEntities(ctxt, buf, XML_SUBSTITUTE_PEREF,
+ 0, 0, 0);
+ --ctxt->depth;
+ if (orig != NULL) {
+ *orig = buf;
+ buf = NULL;
}
+error:
+ if (buf != NULL)
+ xmlFree(buf);
return(ret);
}
@@ -4165,7 +4002,9 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int
normalize) {
ent->checked |= 1;
xmlFree(rep);
rep = NULL;
- }
+ } else {
+ ent->content[0] = 0;
+ }
}
/*
@@ -4589,7 +4428,7 @@ get_more:
if (*in == ']') {
if ((in[1] == ']') && (in[2] == '>')) {
xmlFatalErr(ctxt, XML_ERR_MISPLACED_CDATA_END, NULL);
- ctxt->input->cur = in;
+ ctxt->input->cur = in + 1;
return;
}
in++;
@@ -4782,22 +4621,20 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int
strict) {
*publicID = NULL;
if (CMP6(CUR_PTR, 'S', 'Y', 'S', 'T', 'E',
'M')) {
SKIP(6);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after 'SYSTEM'\n");
}
- SKIP_BLANKS;
URI = xmlParseSystemLiteral(ctxt);
if (URI == NULL) {
xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL);
}
} else if (CMP6(CUR_PTR, 'P', 'U', 'B', 'L',
'I', 'C')) {
SKIP(6);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after 'PUBLIC'\n");
}
- SKIP_BLANKS;
*publicID = xmlParsePubidLiteral(ctxt);
if (*publicID == NULL) {
xmlFatalErr(ctxt, XML_ERR_PUBID_REQUIRED, NULL);
@@ -4806,26 +4643,20 @@ xmlParseExternalID(xmlParserCtxtPtr ctxt, xmlChar **publicID, int
strict) {
/*
* We don't handle [83] so "S SystemLiteral" is required.
*/
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the Public Identifier\n");
}
} else {
/*
* We handle [83] so we return immediately, if
- * "S SystemLiteral" is not detected. From a purely parsing
- * point of view that's a nice mess.
+ * "S SystemLiteral" is not detected. We skip blanks if no
+ * system literal was found, but this is harmless since we must
+ * be at the end of a NotationDecl.
*/
- const xmlChar *ptr;
- GROW;
-
- ptr = CUR_PTR;
- if (!IS_BLANK_CH(*ptr)) return(NULL);
-
- while (IS_BLANK_CH(*ptr)) ptr++; /* TODO: dangerous, fix ! */
- if ((*ptr != '\'') && (*ptr != '"')) return(NULL);
+ if (SKIP_BLANKS == 0) return(NULL);
+ if ((CUR != '\'') && (CUR != '"')) return(NULL);
}
- SKIP_BLANKS;
URI = xmlParseSystemLiteral(ctxt);
if (URI == NULL) {
xmlFatalErr(ctxt, XML_ERR_URI_REQUIRED, NULL);
@@ -4955,7 +4786,8 @@ xmlParseCommentComplex(xmlParserCtxtPtr ctxt, xmlChar *buf,
} else {
if (inputid != ctxt->input->id) {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "Comment doesn't start and stop in the same entity\n");
+ "Comment doesn't start and stop in the same"
+ " entity\n");
}
NEXT;
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
@@ -5103,7 +4935,8 @@ get_more:
if (in[2] == '>') {
if (ctxt->input->id != inputid) {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "comment doesn't start and stop in the same entity\n");
+ "comment doesn't start and stop in the"
+ " same entity\n");
}
SKIP(3);
if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL)
&&
@@ -5271,7 +5104,7 @@ xmlParsePI(xmlParserCtxtPtr ctxt) {
int count = 0;
if ((RAW == '<') && (NXT(1) == '?')) {
- xmlParserInputPtr input = ctxt->input;
+ int inputid = ctxt->input->id;
state = ctxt->instate;
ctxt->instate = XML_PARSER_PI;
/*
@@ -5287,9 +5120,10 @@ xmlParsePI(xmlParserCtxtPtr ctxt) {
target = xmlParsePITarget(ctxt);
if (target != NULL) {
if ((RAW == '?') && (NXT(1) == '>')) {
- if (input != ctxt->input) {
+ if (inputid != ctxt->input->id) {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "PI declaration doesn't start and stop in the same entity\n");
+ "PI declaration doesn't start and stop in"
+ " the same entity\n");
}
SKIP(2);
@@ -5310,12 +5144,10 @@ xmlParsePI(xmlParserCtxtPtr ctxt) {
ctxt->instate = state;
return;
}
- cur = CUR;
- if (!IS_BLANK(cur)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsgStr(ctxt, XML_ERR_SPACE_REQUIRED,
"ParsePI: PI %s space expected\n", target);
}
- SKIP_BLANKS;
cur = CUR_CHAR(l);
while (IS_CHAR(cur) && /* checked */
((cur != '?') || (NXT(1) != '>'))) {
@@ -5371,9 +5203,10 @@ xmlParsePI(xmlParserCtxtPtr ctxt) {
xmlFatalErrMsgStr(ctxt, XML_ERR_PI_NOT_FINISHED,
"ParsePI: PI %s never end ...\n", target);
} else {
- if (input != ctxt->input) {
- xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
- "PI declaration doesn't start and stop in the same entity\n");
+ if (inputid != ctxt->input->id) {
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "PI declaration doesn't start and stop in"
+ " the same entity\n");
}
SKIP(2);
@@ -5429,32 +5262,30 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
xmlChar *Systemid;
if (CMP10(CUR_PTR, '<', '!', 'N', 'O',
'T', 'A', 'T', 'I', 'O', 'N')) {
- xmlParserInputPtr input = ctxt->input;
+ int inputid = ctxt->input->id;
SHRINK;
SKIP(10);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after '<!NOTATION'\n");
return;
}
- SKIP_BLANKS;
name = xmlParseName(ctxt);
if (name == NULL) {
xmlFatalErr(ctxt, XML_ERR_NOTATION_NOT_STARTED, NULL);
return;
}
- if (!IS_BLANK_CH(CUR)) {
- xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
- "Space required after the NOTATION name'\n");
- return;
- }
if (xmlStrchr(name, ':') != NULL) {
xmlNsErr(ctxt, XML_NS_ERR_COLON,
"colons are forbidden from notation names '%s'\n",
name, NULL, NULL);
}
- SKIP_BLANKS;
+ if (SKIP_BLANKS == 0) {
+ xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
+ "Space required after the NOTATION name'\n");
+ return;
+ }
/*
* Parse the IDs.
@@ -5463,9 +5294,10 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
SKIP_BLANKS;
if (RAW == '>') {
- if (input != ctxt->input) {
- xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
- "Notation declaration doesn't start and stop in the same entity\n");
+ if (inputid != ctxt->input->id) {
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "Notation declaration doesn't start and stop"
+ " in the same entity\n");
}
NEXT;
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
@@ -5509,23 +5341,20 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
const xmlChar *ndata = NULL;
int isParameter = 0;
xmlChar *orig = NULL;
- int skipped;
/* GROW; done in the caller */
if (CMP8(CUR_PTR, '<', '!', 'E', 'N', 'T',
'I', 'T', 'Y')) {
- xmlParserInputPtr input = ctxt->input;
+ int inputid = ctxt->input->id;
SHRINK;
SKIP(8);
- skipped = SKIP_BLANKS;
- if (skipped == 0) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after '<!ENTITY'\n");
}
if (RAW == '%') {
NEXT;
- skipped = SKIP_BLANKS;
- if (skipped == 0) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after '%%'\n");
}
@@ -5543,8 +5372,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
"colons are forbidden from entities names '%s'\n",
name, NULL, NULL);
}
- skipped = SKIP_BLANKS;
- if (skipped == 0) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the entity name\n");
}
@@ -5655,18 +5483,16 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
xmlFreeURI(uri);
}
}
- if ((RAW != '>') && (!IS_BLANK_CH(CUR))) {
+ if ((RAW != '>') && (SKIP_BLANKS == 0)) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required before 'NDATA'\n");
}
- SKIP_BLANKS;
if (CMP5(CUR_PTR, 'N', 'D', 'A', 'T', 'A')) {
SKIP(5);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after 'NDATA'\n");
}
- SKIP_BLANKS;
ndata = xmlParseName(ctxt);
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->unparsedEntityDecl != NULL))
@@ -5705,16 +5531,17 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
}
}
if (ctxt->instate == XML_PARSER_EOF)
- return;
+ goto done;
SKIP_BLANKS;
if (RAW != '>') {
xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
"xmlParseEntityDecl: entity %s not terminated\n", name);
xmlHaltParser(ctxt);
} else {
- if (input != ctxt->input) {
+ if (inputid != ctxt->input->id) {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "Entity declaration doesn't start and stop in the same entity\n");
+ "Entity declaration doesn't start and stop in"
+ " the same entity\n");
}
NEXT;
}
@@ -5736,17 +5563,17 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
cur = xmlSAX2GetEntity(ctxt, name);
}
}
- if (cur != NULL) {
- if (cur->orig != NULL)
- xmlFree(orig);
- else
- cur->orig = orig;
- } else
- xmlFree(orig);
+ if ((cur != NULL) && (cur->orig == NULL)) {
+ cur->orig = orig;
+ orig = NULL;
+ }
}
+
+done:
if (value != NULL) xmlFree(value);
if (URI != NULL) xmlFree(URI);
if (literal != NULL) xmlFree(literal);
+ if (orig != NULL) xmlFree(orig);
}
}
@@ -5797,11 +5624,10 @@ xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, xmlChar **value) {
if (CMP6(CUR_PTR, '#', 'F', 'I', 'X', 'E',
'D')) {
SKIP(6);
val = XML_ATTRIBUTE_FIXED;
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after '#FIXED'\n");
}
- SKIP_BLANKS;
}
ret = xmlParseAttValue(ctxt);
ctxt->instate = XML_PARSER_DTD;
@@ -5973,12 +5799,11 @@ int
xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
if (CMP8(CUR_PTR, 'N', 'O', 'T', 'A', 'T',
'I', 'O', 'N')) {
SKIP(8);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after 'NOTATION'\n");
return(0);
}
- SKIP_BLANKS;
*tree = xmlParseNotationType(ctxt);
if (*tree == NULL) return(0);
return(XML_ATTRIBUTE_NOTATION);
@@ -6082,14 +5907,13 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
xmlEnumerationPtr tree;
if (CMP9(CUR_PTR, '<', '!', 'A', 'T', 'T',
'L', 'I', 'S', 'T')) {
- xmlParserInputPtr input = ctxt->input;
+ int inputid = ctxt->input->id;
SKIP(9);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after '<!ATTLIST'\n");
}
- SKIP_BLANKS;
elemName = xmlParseName(ctxt);
if (elemName == NULL) {
xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
@@ -6099,7 +5923,6 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
SKIP_BLANKS;
GROW;
while ((RAW != '>') && (ctxt->instate != XML_PARSER_EOF)) {
- const xmlChar *check = CUR_PTR;
int type;
int def;
xmlChar *defaultValue = NULL;
@@ -6113,12 +5936,11 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
break;
}
GROW;
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the attribute name\n");
break;
}
- SKIP_BLANKS;
type = xmlParseAttributeType(ctxt, &tree);
if (type <= 0) {
@@ -6126,14 +5948,13 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
}
GROW;
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the attribute type\n");
if (tree != NULL)
xmlFreeEnumeration(tree);
break;
}
- SKIP_BLANKS;
def = xmlParseDefaultDecl(ctxt, &defaultValue);
if (def <= 0) {
@@ -6148,7 +5969,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
GROW;
if (RAW != '>') {
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the attribute default value\n");
if (defaultValue != NULL)
@@ -6157,16 +5978,6 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
xmlFreeEnumeration(tree);
break;
}
- SKIP_BLANKS;
- }
- if (check == CUR_PTR) {
- xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
- "in xmlParseAttributeListDecl\n");
- if (defaultValue != NULL)
- xmlFree(defaultValue);
- if (tree != NULL)
- xmlFreeEnumeration(tree);
- break;
}
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->attributeDecl != NULL))
@@ -6188,10 +5999,10 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
GROW;
}
if (RAW == '>') {
- if (input != ctxt->input) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "Attribute list declaration doesn't start and stop in the same
entity\n",
- NULL, NULL);
+ if (inputid != ctxt->input->id) {
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "Attribute list declaration doesn't start
and"
+ " stop in the same entity\n");
}
NEXT;
}
@@ -6228,10 +6039,10 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int
inputchk) {
SKIP_BLANKS;
SHRINK;
if (RAW == ')') {
- if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
-"Element content declaration doesn't start and stop in the same entity\n",
- NULL, NULL);
+ if (ctxt->input->id != inputchk) {
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "Element content declaration doesn't start
and"
+ " stop in the same entity\n");
}
NEXT;
ret = xmlNewDocElementContent(ctxt->myDoc, NULL, XML_ELEMENT_CONTENT_PCDATA);
@@ -6272,7 +6083,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int inputchk)
{
if (elem == NULL) {
xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
"xmlParseElementMixedContentDecl : Name expected\n");
- xmlFreeDocElementContent(ctxt->myDoc, cur);
+ xmlFreeDocElementContent(ctxt->myDoc, ret);
return(NULL);
}
SKIP_BLANKS;
@@ -6287,10 +6098,10 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt, int
inputchk) {
}
if (ret != NULL)
ret->ocur = XML_ELEMENT_CONTENT_MULT;
- if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
-"Element content declaration doesn't start and stop in the same entity\n",
- NULL, NULL);
+ if (ctxt->input->id != inputchk) {
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "Element content declaration doesn't start
and"
+ " stop in the same entity\n");
}
SKIP(2);
} else {
@@ -6530,10 +6341,10 @@ xmlParseElementChildrenContentDeclPriv(xmlParserCtxtPtr ctxt, int
inputchk,
if (last != NULL)
last->parent = cur;
}
- if ((ctxt->validate) && (ctxt->input->id != inputchk)) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
-"Element content declaration doesn't start and stop in the same entity\n",
- NULL, NULL);
+ if (ctxt->input->id != inputchk) {
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "Element content declaration doesn't start and stop
in"
+ " the same entity\n");
}
NEXT;
if (RAW == '?') {
@@ -6706,28 +6517,24 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
/* GROW; done in the caller */
if (CMP9(CUR_PTR, '<', '!', 'E', 'L', 'E',
'M', 'E', 'N', 'T')) {
- xmlParserInputPtr input = ctxt->input;
+ int inputid = ctxt->input->id;
SKIP(9);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after 'ELEMENT'\n");
return(-1);
}
- SKIP_BLANKS;
name = xmlParseName(ctxt);
if (name == NULL) {
xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
"xmlParseElementDecl: no name for Element\n");
return(-1);
}
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space required after the element name\n");
}
- SKIP_BLANKS;
if (CMP5(CUR_PTR, 'E', 'M', 'P', 'T', 'Y')) {
SKIP(5);
/*
@@ -6759,12 +6566,6 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
}
SKIP_BLANKS;
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
- SKIP_BLANKS;
if (RAW != '>') {
xmlFatalErr(ctxt, XML_ERR_GT_REQUIRED, NULL);
@@ -6772,9 +6573,10 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
xmlFreeDocElementContent(ctxt->myDoc, content);
}
} else {
- if (input != ctxt->input) {
+ if (inputid != ctxt->input->id) {
xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "Element declaration doesn't start and stop in the same entity\n");
+ "Element declaration doesn't start and stop
in"
+ " the same entity\n");
}
NEXT;
@@ -6827,9 +6629,9 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
return;
} else {
if (ctxt->input->id != id) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "All markup of the conditional section is not in the same entity\n",
- NULL, NULL);
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "All markup of the conditional section is not"
+ " in the same entity\n");
}
NEXT;
}
@@ -6842,6 +6644,8 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
"Entering INCLUDE Conditional Section\n");
}
+ SKIP_BLANKS;
+ GROW;
while (((RAW != 0) && ((RAW != ']') || (NXT(1) != ']') ||
(NXT(2) != '>'))) && (ctxt->instate != XML_PARSER_EOF)) {
const xmlChar *check = CUR_PTR;
@@ -6849,18 +6653,11 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
if ((RAW == '<') && (NXT(1) == '!') && (NXT(2) ==
'[')) {
xmlParseConditionalSections(ctxt);
- } else if (IS_BLANK_CH(CUR)) {
- NEXT;
- } else if (RAW == '%') {
- xmlParsePEReference(ctxt);
} else
xmlParseMarkupDecl(ctxt);
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
+ SKIP_BLANKS;
+ GROW;
if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
@@ -6890,9 +6687,9 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
return;
} else {
if (ctxt->input->id != id) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "All markup of the conditional section is not in the same entity\n",
- NULL, NULL);
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "All markup of the conditional section is not"
+ " in the same entity\n");
}
NEXT;
}
@@ -6954,9 +6751,9 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
xmlFatalErr(ctxt, XML_ERR_CONDSEC_NOT_FINISHED, NULL);
} else {
if (ctxt->input->id != id) {
- xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "All markup of the conditional section is not in the same entity\n",
- NULL, NULL);
+ xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
+ "All markup of the conditional section is not in"
+ " the same entity\n");
}
if ((ctxt-> instate != XML_PARSER_EOF) &&
((ctxt->input->cur + 3) <= ctxt->input->end))
@@ -7023,13 +6820,6 @@ xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {
if (ctxt->instate == XML_PARSER_EOF)
return;
- /*
- * This is only for internal subset. On external entities,
- * the replacement is done before parsing stage
- */
- if ((ctxt->external == 0) && (ctxt->inputNr == 1))
- xmlParsePEReference(ctxt);
-
/*
* Conditional sections are allowed from entities included
* by PE References in the internal subset.
@@ -7067,11 +6857,10 @@ xmlParseTextDecl(xmlParserCtxtPtr ctxt) {
return;
}
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space needed after '<?xml'\n");
}
- SKIP_BLANKS;
/*
* We may have the VersionInfo here.
@@ -7080,7 +6869,7 @@ xmlParseTextDecl(xmlParserCtxtPtr ctxt) {
if (version == NULL)
version = xmlCharStrdup(XML_DEFAULT_VERSION);
else {
- if (!IS_BLANK_CH(CUR)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"Space needed here\n");
}
@@ -7171,27 +6960,19 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar
*ExternalID,
ctxt->instate = XML_PARSER_DTD;
ctxt->external = 1;
+ SKIP_BLANKS;
while (((RAW == '<') && (NXT(1) == '?')) ||
((RAW == '<') && (NXT(1) == '!')) ||
- (RAW == '%') || IS_BLANK_CH(CUR)) {
+ (RAW == '%')) {
const xmlChar *check = CUR_PTR;
unsigned int cons = ctxt->input->consumed;
GROW;
if ((RAW == '<') && (NXT(1) == '!') && (NXT(2)
== '[')) {
xmlParseConditionalSections(ctxt);
- } else if (IS_BLANK_CH(CUR)) {
- NEXT;
- } else if (RAW == '%') {
- xmlParsePEReference(ctxt);
} else
xmlParseMarkupDecl(ctxt);
-
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
+ SKIP_BLANKS;
if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
@@ -7420,6 +7201,9 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
}
if (ent->checked == 0)
ent->checked = 2;
+
+ /* Prevent entity from being parsed and expanded twice (Bug 760367). */
+ was_checked = 0;
} else if (ent->checked != 1) {
ctxt->nbentities += ent->checked / 2;
}
@@ -8056,12 +7840,14 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
NEXT;
name = xmlParseName(ctxt);
if (name == NULL) {
- xmlFatalErrMsg(ctxt, XML_ERR_NAME_REQUIRED,
- "xmlParsePEReference: no name\n");
+ xmlFatalErrMsg(ctxt, XML_ERR_PEREF_NO_NAME, "PEReference: no name\n");
return;
}
+ if (xmlParserDebugEntities)
+ xmlGenericError(xmlGenericErrorContext,
+ "PEReference: %s\n", name);
if (RAW != ';') {
- xmlFatalErr(ctxt, XML_ERR_ENTITYREF_SEMICOL_MISSING, NULL);
+ xmlFatalErr(ctxt, XML_ERR_PEREF_SEMICOL_MISSING, NULL);
return;
}
@@ -8103,10 +7889,15 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
* ... The declaration of a parameter entity must
* precede any reference to it...
*/
- xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
- "PEReference: %%%s; not found\n",
- name, NULL);
- ctxt->valid = 0;
+ if ((ctxt->validate) && (ctxt->vctxt.error != NULL)) {
+ xmlValidityError(ctxt, XML_WAR_UNDECLARED_ENTITY,
+ "PEReference: %%%s; not found\n",
+ name, NULL);
+ } else
+ xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
+ "PEReference: %%%s; not found\n",
+ name, NULL);
+ ctxt->valid = 0;
}
xmlParserEntityCheck(ctxt, 0, NULL, 0);
} else {
@@ -8118,33 +7909,54 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
xmlWarningMsg(ctxt, XML_WAR_UNDECLARED_ENTITY,
"Internal: %%%s; is not a parameter entity\n",
name, NULL);
- } else if (ctxt->input->free != deallocblankswrapper) {
- input = xmlNewBlanksWrapperInputStream(ctxt, entity);
- if (xmlPushInput(ctxt, input) < 0)
- return;
} else {
- /*
- * TODO !!!
- * handle the extra spaces added before and after
- * c.f.
http://www.w3.org/TR/REC-xml#as-PE
- */
+ xmlChar start[4];
+ xmlCharEncoding enc;
+
+ if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
+ ((ctxt->options & XML_PARSE_NOENT) == 0) &&
+ ((ctxt->options & XML_PARSE_DTDVALID) == 0) &&
+ ((ctxt->options & XML_PARSE_DTDLOAD) == 0) &&
+ ((ctxt->options & XML_PARSE_DTDATTR) == 0) &&
+ (ctxt->replaceEntities == 0) &&
+ (ctxt->validate == 0))
+ return;
+
input = xmlNewEntityInputStream(ctxt, entity);
- if (xmlPushInput(ctxt, input) < 0)
+ if (xmlPushInput(ctxt, input) < 0) {
+ xmlFreeInputStream(input);
return;
- if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
- (CMP5(CUR_PTR, '<', '?', 'x', 'm', 'l'))
&&
- (IS_BLANK_CH(NXT(5)))) {
- xmlParseTextDecl(ctxt);
- if (ctxt->errNo ==
- XML_ERR_UNSUPPORTED_ENCODING) {
- /*
- * The XML REC instructs us to stop parsing
- * right here
- */
- xmlHaltParser(ctxt);
- return;
- }
- }
+ }
+
+ if (entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) {
+ /*
+ * Get the 4 first bytes and decode the charset
+ * if enc != XML_CHAR_ENCODING_NONE
+ * plug some encoding conversion routines.
+ * Note that, since we may have some non-UTF8
+ * encoding (like UTF16, bug 135229), the 'length'
+ * is not known, but we can calculate based upon
+ * the amount of data in the buffer.
+ */
+ GROW
+ if (ctxt->instate == XML_PARSER_EOF)
+ return;
+ if ((ctxt->input->end - ctxt->input->cur)>=4) {
+ start[0] = RAW;
+ start[1] = NXT(1);
+ start[2] = NXT(2);
+ start[3] = NXT(3);
+ enc = xmlDetectCharEncoding(start, 4);
+ if (enc != XML_CHAR_ENCODING_NONE) {
+ xmlSwitchEncoding(ctxt, enc);
+ }
+ }
+
+ if ((CMP5(CUR_PTR, '<', '?', 'x', 'm',
'l')) &&
+ (IS_BLANK_CH(NXT(5)))) {
+ xmlParseTextDecl(ctxt);
+ }
+ }
}
}
ctxt->hasPErefs = 1;
@@ -8320,6 +8132,7 @@ xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar
**str) {
entity = ctxt->sax->getParameterEntity(ctxt->userData, name);
if (ctxt->instate == XML_PARSER_EOF) {
xmlFree(name);
+ *str = ptr;
return(NULL);
}
if (entity == NULL) {
@@ -8458,6 +8271,7 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
* Is there any DTD definition ?
*/
if (RAW == '[') {
+ int baseInputNr = ctxt->inputNr;
ctxt->instate = XML_PARSER_DTD;
NEXT;
/*
@@ -8465,7 +8279,8 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
* PEReferences.
* Subsequence (markupdecl | PEReference | S)*
*/
- while ((RAW != ']') && (ctxt->instate != XML_PARSER_EOF)) {
+ while (((RAW != ']') || (ctxt->inputNr > baseInputNr)) &&
+ (ctxt->instate != XML_PARSER_EOF)) {
const xmlChar *check = CUR_PTR;
unsigned int cons = ctxt->input->consumed;
@@ -8473,16 +8288,13 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
xmlParseMarkupDecl(ctxt);
xmlParsePEReference(ctxt);
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
-
if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
"xmlParseInternalSubset: error detected in Markup declaration\n");
- break;
+ if (ctxt->inputNr > baseInputNr)
+ xmlPopInput(ctxt);
+ else
+ break;
}
}
if (RAW == ']') {
@@ -8560,7 +8372,7 @@ xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlChar **value) {
ctxt->instate = XML_PARSER_CONTENT;
} else {
xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE,
- "Specification mandate value for attribute %s\n", name);
+ "Specification mandates value for attribute %s\n", name);
return(NULL);
}
@@ -8717,11 +8529,10 @@ failed:
GROW
if ((RAW == '>') || (((RAW == '/') && (NXT(1) ==
'>'))))
break;
- if (!IS_BLANK_CH(RAW)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"attributes construct error\n");
}
- SKIP_BLANKS;
if ((cons == ctxt->input->consumed) && (q == CUR_PTR) &&
(attname == NULL) && (attvalue == NULL)) {
xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
@@ -9259,8 +9070,8 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt,
if (ctxt->attsSpecial != NULL) {
int type;
- type = (int) (long) xmlHashQLookup2(ctxt->attsSpecial,
- pref, elem, *prefix, name);
+ type = (int) (ptrdiff_t) xmlHashQLookup2(ctxt->attsSpecial,
+ pref, elem, *prefix, name);
if (type != 0)
normalize = 1;
}
@@ -9293,7 +9104,7 @@ xmlParseAttribute2(xmlParserCtxtPtr ctxt,
ctxt->instate = XML_PARSER_CONTENT;
} else {
xmlFatalErrMsgStr(ctxt, XML_ERR_ATTRIBUTE_WITHOUT_VALUE,
- "Specification mandate value for attribute %s\n",
+ "Specification mandates value for attribute %s\n",
name);
return (NULL);
}
@@ -9376,9 +9187,8 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,
xmlChar *attvalue;
const xmlChar **atts = ctxt->atts;
int maxatts = ctxt->maxatts;
- int nratts, nbatts, nbdef;
- int i, j, nbNs, attval, oldline, oldcol, inputNr;
- const xmlChar *base;
+ int nratts, nbatts, nbdef, inputid;
+ int i, j, nbNs, attval;
unsigned long cur;
int nsNr = ctxt->nsNr;
@@ -9392,13 +9202,9 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,
* The Shrinking is only possible once the full set of attribute
* callbacks have been done.
*/
-reparse:
SHRINK;
- base = ctxt->input->base;
cur = ctxt->input->cur - ctxt->input->base;
- inputNr = ctxt->inputNr;
- oldline = ctxt->input->line;
- oldcol = ctxt->input->col;
+ inputid = ctxt->input->id;
nbatts = 0;
nratts = 0;
nbdef = 0;
@@ -9422,8 +9228,6 @@ reparse:
*/
SKIP_BLANKS;
GROW;
- if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
- goto base_changed;
while (((RAW != '>') &&
((RAW != '/') || (NXT(1) != '>')) &&
@@ -9434,211 +9238,181 @@ reparse:
attname = xmlParseAttribute2(ctxt, prefix, localname,
&aprefix, &attvalue, &len, &alloc);
- if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr)) {
- if ((attvalue != NULL) && (alloc != 0))
- xmlFree(attvalue);
- attvalue = NULL;
- goto base_changed;
- }
- if ((attname != NULL) && (attvalue != NULL)) {
- if (len < 0) len = xmlStrlen(attvalue);
- if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
- const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
- xmlURIPtr uri;
-
- if (URL == NULL) {
- xmlErrMemory(ctxt, "dictionary allocation failure");
- if ((attvalue != NULL) && (alloc != 0))
- xmlFree(attvalue);
- return(NULL);
- }
- if (*URL != 0) {
- uri = xmlParseURI((const char *) URL);
- if (uri == NULL) {
- xmlNsErr(ctxt, XML_WAR_NS_URI,
- "xmlns: '%s' is not a valid URI\n",
- URL, NULL, NULL);
- } else {
- if (uri->scheme == NULL) {
- xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
- "xmlns: URI %s is not absolute\n",
- URL, NULL, NULL);
- }
- xmlFreeURI(uri);
- }
- if (URL == ctxt->str_xml_ns) {
- if (attname != ctxt->str_xml) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "xml namespace URI cannot be the default namespace\n",
- NULL, NULL, NULL);
- }
- goto skip_default_ns;
- }
- if ((len == 29) &&
- (xmlStrEqual(URL,
- BAD_CAST "http://www.w3.org/2000/xmlns/"))) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "reuse of the xmlns namespace name is forbidden\n",
- NULL, NULL, NULL);
- goto skip_default_ns;
- }
- }
- /*
- * check that it's not a defined namespace
- */
- for (j = 1;j <= nbNs;j++)
- if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL)
- break;
- if (j <= nbNs)
- xmlErrAttributeDup(ctxt, NULL, attname);
- else
- if (nsPush(ctxt, NULL, URL) > 0) nbNs++;
-skip_default_ns:
- if ((attvalue != NULL) && (alloc != 0)) {
- xmlFree(attvalue);
- attvalue = NULL;
- }
- if ((RAW == '>') || (((RAW == '/') && (NXT(1) ==
'>'))))
- break;
- if (!IS_BLANK_CH(RAW)) {
- xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
- "attributes construct error\n");
- break;
- }
- SKIP_BLANKS;
- if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
- goto base_changed;
- continue;
- }
- if (aprefix == ctxt->str_xmlns) {
- const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
- xmlURIPtr uri;
-
- if (attname == ctxt->str_xml) {
- if (URL != ctxt->str_xml_ns) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "xml namespace prefix mapped to wrong URI\n",
- NULL, NULL, NULL);
- }
- /*
- * Do not keep a namespace definition node
- */
- goto skip_ns;
- }
+ if ((attname == NULL) || (attvalue == NULL))
+ goto next_attr;
+ if (len < 0) len = xmlStrlen(attvalue);
+
+ if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) {
+ const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
+ xmlURIPtr uri;
+
+ if (URL == NULL) {
+ xmlErrMemory(ctxt, "dictionary allocation failure");
+ if ((attvalue != NULL) && (alloc != 0))
+ xmlFree(attvalue);
+ return(NULL);
+ }
+ if (*URL != 0) {
+ uri = xmlParseURI((const char *) URL);
+ if (uri == NULL) {
+ xmlNsErr(ctxt, XML_WAR_NS_URI,
+ "xmlns: '%s' is not a valid URI\n",
+ URL, NULL, NULL);
+ } else {
+ if (uri->scheme == NULL) {
+ xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
+ "xmlns: URI %s is not absolute\n",
+ URL, NULL, NULL);
+ }
+ xmlFreeURI(uri);
+ }
if (URL == ctxt->str_xml_ns) {
- if (attname != ctxt->str_xml) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "xml namespace URI mapped to wrong prefix\n",
- NULL, NULL, NULL);
- }
- goto skip_ns;
- }
- if (attname == ctxt->str_xmlns) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "redefinition of the xmlns prefix is forbidden\n",
- NULL, NULL, NULL);
- goto skip_ns;
- }
- if ((len == 29) &&
- (xmlStrEqual(URL,
- BAD_CAST "http://www.w3.org/2000/xmlns/"))) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "reuse of the xmlns namespace name is forbidden\n",
- NULL, NULL, NULL);
- goto skip_ns;
- }
- if ((URL == NULL) || (URL[0] == 0)) {
- xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
- "xmlns:%s: Empty XML namespace is not allowed\n",
- attname, NULL, NULL);
- goto skip_ns;
- } else {
- uri = xmlParseURI((const char *) URL);
- if (uri == NULL) {
- xmlNsErr(ctxt, XML_WAR_NS_URI,
- "xmlns:%s: '%s' is not a valid URI\n",
- attname, URL, NULL);
- } else {
- if ((ctxt->pedantic) && (uri->scheme == NULL)) {
- xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
- "xmlns:%s: URI %s is not absolute\n",
- attname, URL, NULL);
- }
- xmlFreeURI(uri);
- }
- }
-
- /*
- * check that it's not a defined namespace
- */
- for (j = 1;j <= nbNs;j++)
- if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname)
- break;
- if (j <= nbNs)
- xmlErrAttributeDup(ctxt, aprefix, attname);
- else
- if (nsPush(ctxt, attname, URL) > 0) nbNs++;
-skip_ns:
- if ((attvalue != NULL) && (alloc != 0)) {
- xmlFree(attvalue);
- attvalue = NULL;
- }
- if ((RAW == '>') || (((RAW == '/') && (NXT(1) ==
'>'))))
- break;
- if (!IS_BLANK_CH(RAW)) {
- xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
- "attributes construct error\n");
- break;
- }
- SKIP_BLANKS;
- if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
- goto base_changed;
- continue;
- }
+ if (attname != ctxt->str_xml) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "xml namespace URI cannot be the default namespace\n",
+ NULL, NULL, NULL);
+ }
+ goto next_attr;
+ }
+ if ((len == 29) &&
+ (xmlStrEqual(URL,
+ BAD_CAST "http://www.w3.org/2000/xmlns/"))) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "reuse of the xmlns namespace name is forbidden\n",
+ NULL, NULL, NULL);
+ goto next_attr;
+ }
+ }
+ /*
+ * check that it's not a defined namespace
+ */
+ for (j = 1;j <= nbNs;j++)
+ if (ctxt->nsTab[ctxt->nsNr - 2 * j] == NULL)
+ break;
+ if (j <= nbNs)
+ xmlErrAttributeDup(ctxt, NULL, attname);
+ else
+ if (nsPush(ctxt, NULL, URL) > 0) nbNs++;
+
+ } else if (aprefix == ctxt->str_xmlns) {
+ const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len);
+ xmlURIPtr uri;
+
+ if (attname == ctxt->str_xml) {
+ if (URL != ctxt->str_xml_ns) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "xml namespace prefix mapped to wrong URI\n",
+ NULL, NULL, NULL);
+ }
+ /*
+ * Do not keep a namespace definition node
+ */
+ goto next_attr;
+ }
+ if (URL == ctxt->str_xml_ns) {
+ if (attname != ctxt->str_xml) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "xml namespace URI mapped to wrong prefix\n",
+ NULL, NULL, NULL);
+ }
+ goto next_attr;
+ }
+ if (attname == ctxt->str_xmlns) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "redefinition of the xmlns prefix is forbidden\n",
+ NULL, NULL, NULL);
+ goto next_attr;
+ }
+ if ((len == 29) &&
+ (xmlStrEqual(URL,
+ BAD_CAST "http://www.w3.org/2000/xmlns/"))) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "reuse of the xmlns namespace name is forbidden\n",
+ NULL, NULL, NULL);
+ goto next_attr;
+ }
+ if ((URL == NULL) || (URL[0] == 0)) {
+ xmlNsErr(ctxt, XML_NS_ERR_XML_NAMESPACE,
+ "xmlns:%s: Empty XML namespace is not allowed\n",
+ attname, NULL, NULL);
+ goto next_attr;
+ } else {
+ uri = xmlParseURI((const char *) URL);
+ if (uri == NULL) {
+ xmlNsErr(ctxt, XML_WAR_NS_URI,
+ "xmlns:%s: '%s' is not a valid URI\n",
+ attname, URL, NULL);
+ } else {
+ if ((ctxt->pedantic) && (uri->scheme == NULL)) {
+ xmlNsWarn(ctxt, XML_WAR_NS_URI_RELATIVE,
+ "xmlns:%s: URI %s is not absolute\n",
+ attname, URL, NULL);
+ }
+ xmlFreeURI(uri);
+ }
+ }
- /*
- * Add the pair to atts
- */
- if ((atts == NULL) || (nbatts + 5 > maxatts)) {
- if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
- if (attvalue[len] == 0)
- xmlFree(attvalue);
- goto failed;
- }
- maxatts = ctxt->maxatts;
- atts = ctxt->atts;
- }
- ctxt->attallocs[nratts++] = alloc;
- atts[nbatts++] = attname;
- atts[nbatts++] = aprefix;
- atts[nbatts++] = NULL; /* the URI will be fetched later */
- atts[nbatts++] = attvalue;
- attvalue += len;
- atts[nbatts++] = attvalue;
- /*
- * tag if some deallocation is needed
- */
- if (alloc != 0) attval = 1;
- } else {
- if ((attvalue != NULL) && (attvalue[len] == 0))
- xmlFree(attvalue);
- }
+ /*
+ * check that it's not a defined namespace
+ */
+ for (j = 1;j <= nbNs;j++)
+ if (ctxt->nsTab[ctxt->nsNr - 2 * j] == attname)
+ break;
+ if (j <= nbNs)
+ xmlErrAttributeDup(ctxt, aprefix, attname);
+ else
+ if (nsPush(ctxt, attname, URL) > 0) nbNs++;
+
+ } else {
+ /*
+ * Add the pair to atts
+ */
+ if ((atts == NULL) || (nbatts + 5 > maxatts)) {
+ if (xmlCtxtGrowAttrs(ctxt, nbatts + 5) < 0) {
+ goto next_attr;
+ }
+ maxatts = ctxt->maxatts;
+ atts = ctxt->atts;
+ }
+ ctxt->attallocs[nratts++] = alloc;
+ atts[nbatts++] = attname;
+ atts[nbatts++] = aprefix;
+ /*
+ * The namespace URI field is used temporarily to point at the
+ * base of the current input buffer for non-alloced attributes.
+ * When the input buffer is reallocated, all the pointers become
+ * invalid, but they can be reconstructed later.
+ */
+ if (alloc)
+ atts[nbatts++] = NULL;
+ else
+ atts[nbatts++] = ctxt->input->base;
+ atts[nbatts++] = attvalue;
+ attvalue += len;
+ atts[nbatts++] = attvalue;
+ /*
+ * tag if some deallocation is needed
+ */
+ if (alloc != 0) attval = 1;
+ attvalue = NULL; /* moved into atts */
+ }
-failed:
+next_attr:
+ if ((attvalue != NULL) && (alloc != 0)) {
+ xmlFree(attvalue);
+ attvalue = NULL;
+ }
GROW
if (ctxt->instate == XML_PARSER_EOF)
break;
- if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
- goto base_changed;
if ((RAW == '>') || (((RAW == '/') && (NXT(1) ==
'>'))))
break;
- if (!IS_BLANK_CH(RAW)) {
+ if (SKIP_BLANKS == 0) {
xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
"attributes construct error\n");
break;
}
- SKIP_BLANKS;
if ((cons == ctxt->input->consumed) && (q == CUR_PTR) &&
(attname == NULL) && (attvalue == NULL)) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
@@ -9646,8 +9420,27 @@ failed:
break;
}
GROW;
- if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
- goto base_changed;
+ }
+
+ if (ctxt->input->id != inputid) {
+ xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
+ "Unexpected change of input\n");
+ localname = NULL;
+ goto done;
+ }
+
+ /* Reconstruct attribute value pointers. */
+ for (i = 0, j = 0; j < nratts; i += 5, j++) {
+ if (atts[i+2] != NULL) {
+ /*
+ * Arithmetic on dangling pointers is technically undefined
+ * behavior, but well...
+ */
+ ptrdiff_t offset = ctxt->input->base - atts[i+2];
+ atts[i+2] = NULL; /* Reset repurposed namespace URI */
+ atts[i+3] += offset; /* value */
+ atts[i+4] += offset; /* valuend */
+ }
}
/*
@@ -9794,6 +9587,7 @@ failed:
nsname, 0, NULL, nbatts / 5, nbdef, atts);
}
+done:
/*
* Free up attribute allocated strings if needed
*/
@@ -9804,34 +9598,6 @@ failed:
}
return(localname);
-
-base_changed:
- /*
- * the attribute strings are valid iif the base didn't changed
- */
- if (attval != 0) {
- for (i = 3,j = 0; j < nratts;i += 5,j++)
- if ((ctxt->attallocs[j] != 0) && (atts[i] != NULL))
- xmlFree((xmlChar *) atts[i]);
- }
-
- /*
- * We can't switch from one entity to another in the middle
- * of a start tag
- */
- if (inputNr != ctxt->inputNr) {
- xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
- "Start tag doesn't start and stop in the same entity\n");
- return(NULL);
- }
-
- ctxt->input->cur = ctxt->input->base + cur;
- ctxt->input->line = oldline;
- ctxt->input->col = oldcol;
- if (ctxt->wellFormed == 1) {
- goto reparse;
- }
- return(NULL);
}
/**
@@ -10100,11 +9866,6 @@ xmlParseContent(xmlParserCtxtPtr ctxt) {
}
GROW;
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
SHRINK;
if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
@@ -11257,7 +11018,7 @@ xmlParseGetLasts(xmlParserCtxtPtr ctxt, const xmlChar **lastlt,
* Check that the block of characters is okay as SCdata content [20]
*
* Returns the number of bytes to pass if okay, a negative index where an
- * UTF-8 error occured otherwise
+ * UTF-8 error occurred otherwise
*/
static int
xmlCheckCdataPush(const xmlChar *utf, int len, int complete) {
@@ -11399,13 +11160,6 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
return(0);
-
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
-
if (ctxt->input == NULL) break;
if (ctxt->input->buf == NULL)
avail = ctxt->input->length -
@@ -11756,11 +11510,6 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
ctxt->checkIndex = 0;
xmlParseCharData(ctxt, 0);
}
- /*
- * Pop-up of finished entities.
- */
- while ((RAW == 0) && (ctxt->inputNr > 1))
- xmlPopInput(ctxt);
if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
"detected an error in element content\n");
@@ -11783,9 +11532,10 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
}
if (ctxt->sax2) {
xmlParseEndTag2(ctxt,
- (void *) ctxt->pushTab[ctxt->nameNr * 3 - 3],
- (void *) ctxt->pushTab[ctxt->nameNr * 3 - 2], 0,
- (int) (long) ctxt->pushTab[ctxt->nameNr * 3 - 1], 0);
+ (void *) ctxt->pushTab[ctxt->nameNr * 3 - 3],
+ (void *) ctxt->pushTab[ctxt->nameNr * 3 - 2], 0,
+ (int) (ptrdiff_t)
+ ctxt->pushTab[ctxt->nameNr * 3 - 1], 0);
nameNsPop(ctxt);
}
#ifdef LIBXML_SAX1_ENABLED
@@ -12703,6 +12453,8 @@ xmlHaltParser(xmlParserCtxtPtr ctxt) {
return;
ctxt->instate = XML_PARSER_EOF;
ctxt->disableSAX = 1;
+ while (ctxt->inputNr > 1)
+ xmlFreeInputStream(inputPop(ctxt));
if (ctxt->input != NULL) {
/*
* in case there was a specific allocation deallocate before
@@ -12714,6 +12466,7 @@ xmlHaltParser(xmlParserCtxtPtr ctxt) {
}
ctxt->input->cur = BAD_CAST"";
ctxt->input->base = ctxt->input->cur;
+ ctxt->input->end = ctxt->input->cur;
}
}
@@ -13482,7 +13235,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr
oldctxt,
/*
* And record the last error if any
*/
- if (ctxt->lastError.code != XML_ERR_OK)
+ if ((oldctxt != NULL) && (ctxt->lastError.code != XML_ERR_OK))
xmlCopyError(&ctxt->lastError, &oldctxt->lastError);
if (sax != NULL)
diff --git a/sdk/lib/3rdparty/libxml2/parserInternals.c
b/sdk/lib/3rdparty/libxml2/parserInternals.c
index bfc778ac1f..efb23872a5 100644
--- a/sdk/lib/3rdparty/libxml2/parserInternals.c
+++ b/sdk/lib/3rdparty/libxml2/parserInternals.c
@@ -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) {
diff --git a/sdk/lib/3rdparty/libxml2/pattern.c b/sdk/lib/3rdparty/libxml2/pattern.c
index 33dee3aace..0eb8d81244 100644
--- a/sdk/lib/3rdparty/libxml2/pattern.c
+++ b/sdk/lib/3rdparty/libxml2/pattern.c
@@ -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;
}
diff --git a/sdk/lib/3rdparty/libxml2/relaxng.c b/sdk/lib/3rdparty/libxml2/relaxng.c
index 3d3e69c0e3..b12e1ae363 100644
--- a/sdk/lib/3rdparty/libxml2/relaxng.c
+++ b/sdk/lib/3rdparty/libxml2/relaxng.c
@@ -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;
diff --git a/sdk/lib/3rdparty/libxml2/threads.c b/sdk/lib/3rdparty/libxml2/threads.c
index ddbb138c58..95432d0d04 100644
--- a/sdk/lib/3rdparty/libxml2/threads.c
+++ b/sdk/lib/3rdparty/libxml2/threads.c
@@ -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) {
diff --git a/sdk/lib/3rdparty/libxml2/timsort.h b/sdk/lib/3rdparty/libxml2/timsort.h
index 795f272144..0c6346b8a6 100644
--- a/sdk/lib/3rdparty/libxml2/timsort.h
+++ b/sdk/lib/3rdparty/libxml2/timsort.h
@@ -1,312 +1,350 @@
/*
- * 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
+
+#ifndef SORT_NAME
+#error "Must declare SORT_NAME"
#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
+#ifndef SORT_TYPE
+#error "Must declare SORT_TYPE"
#endif
+
+#ifndef SORT_CMP
+#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
-int compute_minrun(uint64_t);
+static int compute_minrun(const uint64_t);
#ifndef CLZ
-#if defined(__GNUC__) && ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) ||
(__GNUC__ > 3))
+#ifdef __GNUC__
#define CLZ __builtin_clzll
#else
-int clzll(uint64_t);
+static int clzll(uint64_t);
/* adapted from Hacker's Delight */
-int clzll(uint64_t x) /* {{{ */
-{
+static int clzll(uint64_t x) {
int n;
- if (x == 0) return(64);
+ 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;}
+
+ 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
-int compute_minrun(uint64_t size) /* {{{ */
-{
+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 = (MK_UINT64(1) << shift) - 1;
- if (mask & size) return minrun + 1;
- return minrun;
-}
-/* }}} */
-
-#ifndef SORT_NAME
-#error "Must declare SORT_NAME"
-#endif
+ const uint64_t mask = (1ULL << shift) - 1;
-#ifndef SORT_TYPE
-#error "Must declare SORT_TYPE"
-#endif
-
-#ifndef SORT_CMP
-#define SORT_CMP(x, y) ((x) < (y) ? -1 : ((x) == (y) ? 0 : 1))
-#endif
+ if (mask & size) {
+ return minrun + 1;
+ }
+ return minrun;
+}
-#define SORT_SWAP(x,y) {SORT_TYPE __SORT_SWAP_t = (x); (x) = (y); (y) = __SORT_SWAP_t;}
+#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)
-{
- 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;
+static int CHECK_INVARIANT(TIM_SORT_RUN_T *stack, const int stack_curr) {
+ size_t A, B, C;
+
+ 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;
-
- 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--];
+ i = B;
+ j = curr + A;
+ k = curr + A + B;
+
+ 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;
+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 (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) {
... 3306 lines suppressed ...