rolled back to 2.9.1 because 2.9.2 doesn't work with connecting net
[platform/upstream/libxml2.git] / parser.c
index 53a6b7f..ee429f3 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -94,8 +94,6 @@ static xmlParserCtxtPtr
 xmlCreateEntityParserCtxtInternal(const xmlChar *URL, const xmlChar *ID,
                          const xmlChar *base, xmlParserCtxtPtr pctx);
 
-static void xmlHaltParser(xmlParserCtxtPtr ctxt);
-
 /************************************************************************
  *                                                                     *
  *     Arbitrary limits set in the parser. See XML_PARSE_HUGE          *
@@ -132,35 +130,6 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
         return (0);
     if (ctxt->lastError.code == XML_ERR_ENTITY_LOOP)
         return (1);
-
-    /*
-     * This may look absurd but is needed to detect
-     * entities problems
-     */
-    if ((ent != NULL) && (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) &&
-       (ent->content != NULL) && (ent->checked == 0) &&
-       (ctxt->errNo != XML_ERR_ENTITY_LOOP)) {
-       unsigned long oldnbent = ctxt->nbentities;
-       xmlChar *rep;
-
-       ent->checked = 1;
-
-        ++ctxt->depth;
-       rep = xmlStringDecodeEntities(ctxt, ent->content,
-                                 XML_SUBSTITUTE_REF, 0, 0, 0);
-        --ctxt->depth;
-       if (ctxt->errNo == XML_ERR_ENTITY_LOOP) {
-           ent->content[0] = 0;
-       }
-
-       ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
-       if (rep != NULL) {
-           if (xmlStrchr(rep, '<'))
-               ent->checked |= 1;
-           xmlFree(rep);
-           rep = NULL;
-       }
-    }
     if (replacement != 0) {
        if (replacement < XML_MAX_TEXT_LENGTH)
            return(0);
@@ -220,12 +189,9 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
             return (0);
     } else {
         /*
-         * strange we got no data for checking
+         * strange we got no data for checking just return
          */
-       if (((ctxt->lastError.code != XML_ERR_UNDECLARED_ENTITY) &&
-            (ctxt->lastError.code != XML_WAR_UNDECLARED_ENTITY)) ||
-           (ctxt->nbentities <= 10000))
-           return (0);
+        return (0);
     }
     xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
     return (1);
@@ -350,6 +316,7 @@ static void
 xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
 {
     const char *errmsg;
+    char errstr[129] = "";
 
     if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
         (ctxt->instate == XML_PARSER_EOF))
@@ -536,17 +503,15 @@ xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
         default:
             errmsg = "Unregistered error message";
     }
+    if (info == NULL)
+        snprintf(errstr, 128, "%s\n", errmsg);
+    else
+        snprintf(errstr, 128, "%s: %%s\n", errmsg);
     if (ctxt != NULL)
        ctxt->errNo = error;
-    if (info == NULL) {
-        __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
-                        XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, "%s\n",
-                        errmsg);
-    } else {
-        __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
-                        XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, "%s: %s\n",
-                        errmsg, info);
-    }
+    __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER, error,
+                    XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, &errstr[0],
+                    info);
     if (ctxt != NULL) {
        ctxt->wellFormed = 0;
        if (ctxt->recovery == 0)
@@ -562,7 +527,7 @@ xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
  *
  * Handle a fatal parser error, i.e. violating Well-Formedness constraints
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                const char *msg)
 {
@@ -590,7 +555,7 @@ xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a warning.
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
               const char *msg, const xmlChar *str1, const xmlChar *str2)
 {
@@ -628,7 +593,7 @@ xmlWarningMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a validity error.
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
               const char *msg, const xmlChar *str1, const xmlChar *str2)
 {
@@ -668,7 +633,7 @@ xmlValidityError(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a fatal parser error, i.e. violating Well-Formedness constraints
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, int val)
 {
@@ -698,7 +663,7 @@ xmlFatalErrMsgInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a fatal parser error, i.e. violating Well-Formedness constraints
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, const xmlChar *str1, int val,
                  const xmlChar *str2)
@@ -728,7 +693,7 @@ xmlFatalErrMsgStrIntStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a fatal parser error, i.e. violating Well-Formedness constraints
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, const xmlChar * val)
 {
@@ -757,7 +722,7 @@ xmlFatalErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a non fatal parser error
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
                   const char *msg, const xmlChar * val)
 {
@@ -782,7 +747,7 @@ xmlErrMsgStr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a fatal parser error, i.e. violating Well-Formedness constraints
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlNsErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
          const char *msg,
          const xmlChar * info1, const xmlChar * info2,
@@ -811,7 +776,7 @@ xmlNsErr(xmlParserCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a namespace warning error
  */
-static void LIBXML_ATTR_FORMAT(3,0)
+static void
 xmlNsWarn(xmlParserCtxtPtr ctxt, xmlParserErrors error,
          const char *msg,
          const xmlChar * info1, const xmlChar * info2,
@@ -1780,7 +1745,7 @@ nodePush(xmlParserCtxtPtr ctxt, xmlNodePtr value)
        xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
                 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
                          xmlParserMaxDepth);
-       xmlHaltParser(ctxt);
+       ctxt->instate = XML_PARSER_EOF;
        return(-1);
     }
     ctxt->nodeTab[ctxt->nodeNr] = value;
@@ -2015,7 +1980,6 @@ static int spacePop(xmlParserCtxtPtr ctxt) {
 #define CUR (*ctxt->input->cur)
 #define NXT(val) ctxt->input->cur[(val)]
 #define CUR_PTR ctxt->input->cur
-#define BASE_PTR ctxt->input->base
 
 #define CMP4( s, c1, c2, c3, c4 ) \
   ( ((unsigned char *) s)[ 0 ] == c1 && ((unsigned char *) s)[ 1 ] == c2 && \
@@ -2075,24 +2039,14 @@ static void xmlSHRINK (xmlParserCtxtPtr ctxt) {
        xmlGROW (ctxt);
 
 static void xmlGROW (xmlParserCtxtPtr ctxt) {
-    unsigned long curEnd = ctxt->input->end - ctxt->input->cur;
-    unsigned long curBase = ctxt->input->cur - ctxt->input->base;
-
-    if (((curEnd > (unsigned long) XML_MAX_LOOKUP_LIMIT) ||
-         (curBase > (unsigned long) XML_MAX_LOOKUP_LIMIT)) &&
+    if ((((ctxt->input->end - ctxt->input->cur) > XML_MAX_LOOKUP_LIMIT) ||
+         ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
          ((ctxt->input->buf) && (ctxt->input->buf->readcallback != (xmlInputReadCallback) xmlNop)) &&
         ((ctxt->options & XML_PARSE_HUGE) == 0)) {
         xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
-        xmlHaltParser(ctxt);
-       return;
+        ctxt->instate = XML_PARSER_EOF;
     }
     xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
-    if ((ctxt->input->cur > ctxt->input->end) ||
-        (ctxt->input->cur < ctxt->input->base)) {
-        xmlHaltParser(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);
@@ -2152,8 +2106,6 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
        while (IS_BLANK_CH(*cur)) {
            if (*cur == '\n') {
                ctxt->input->line++; ctxt->input->col = 1;
-           } else {
-               ctxt->input->col++;
            }
            cur++;
            res++;
@@ -2168,8 +2120,7 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
        int cur;
        do {
            cur = CUR;
-           while ((IS_BLANK_CH(cur) && /* CHECKED tstblanks.xml */
-                  (ctxt->instate != XML_PARSER_EOF))) {
+           while (IS_BLANK_CH(cur)) { /* CHECKED tstblanks.xml */
                NEXT;
                cur = CUR;
                res++;
@@ -2183,8 +2134,7 @@ xmlSkipBlankChars(xmlParserCtxtPtr ctxt) {
             * 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));
+       } while (IS_BLANK(cur)); /* CHECKED tstblanks.xml */
     }
     return(res);
 }
@@ -2634,7 +2584,6 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
                                      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)
@@ -2646,23 +2595,6 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) {
                    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.
@@ -2805,7 +2737,6 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
            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;
            if ((ent != NULL) &&
@@ -2825,10 +2756,6 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
                                              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 */
@@ -2861,26 +2788,11 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len,
            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;
            if (ent != NULL) {
                 if (ent->content == NULL) {
-                   /*
-                    * Note: external parsed entities will not be loaded,
-                    * it is not required for a non-validating parser to
-                    * complete external PEreferences coming from the
-                    * internal subset
-                    */
-                   if (((ctxt->options & XML_PARSE_NOENT) != 0) ||
-                       ((ctxt->options & XML_PARSE_DTDVALID) != 0) ||
-                       (ctxt->validate != 0)) {
-                       xmlLoadEntityContent(ctxt, ent);
-                   } else {
-                       xmlWarningMsg(ctxt, XML_ERR_ENTITY_PROCESSING,
-                 "not validating will not read content for PE entity %s\n",
-                                     ent->name, NULL);
-                   }
+                   xmlLoadEntityContent(ctxt, ent);
                }
                ctxt->depth++;
                rep = xmlStringDecodeEntities(ctxt, ent->content, what,
@@ -3492,7 +3404,6 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
     int len = 0, l;
     int c;
     int count = 0;
-    size_t startPosition = 0;
 
 #ifdef DEBUG
     nbParseNCNameComplex++;
@@ -3502,7 +3413,6 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
      * Handler for more complex cases
      */
     GROW;
-    startPosition = CUR_PTR - BASE_PTR;
     c = CUR_CHAR(l);
     if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
        (!xmlIsNameStartChar(ctxt, c) || (c == ':'))) {
@@ -3527,14 +3437,7 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
        c = CUR_CHAR(l);
        if (c == 0) {
            count = 0;
-           /*
-            * when shrinking to extend the buffer we really need to preserve
-            * the part of the name we already parsed. Hence rolling back
-            * by current lenght.
-            */
-           ctxt->input->cur -= l;
            GROW;
-           ctxt->input->cur += l;
             if (ctxt->instate == XML_PARSER_EOF)
                 return(NULL);
            c = CUR_CHAR(l);
@@ -3545,7 +3448,7 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
         xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
         return(NULL);
     }
-    return(xmlDictLookup(ctxt->dict, (BASE_PTR + startPosition), len));
+    return(xmlDictLookup(ctxt->dict, ctxt->input->cur - len, len));
 }
 
 /**
@@ -3565,7 +3468,7 @@ xmlParseNCNameComplex(xmlParserCtxtPtr ctxt) {
 
 static const xmlChar *
 xmlParseNCName(xmlParserCtxtPtr ctxt) {
-    const xmlChar *in, *e;
+    const xmlChar *in;
     const xmlChar *ret;
     int count = 0;
 
@@ -3577,19 +3480,16 @@ xmlParseNCName(xmlParserCtxtPtr ctxt) {
      * Accelerator for simple ASCII names
      */
     in = ctxt->input->cur;
-    e = ctxt->input->end;
-    if ((((*in >= 0x61) && (*in <= 0x7A)) ||
-        ((*in >= 0x41) && (*in <= 0x5A)) ||
-        (*in == '_')) && (in < e)) {
+    if (((*in >= 0x61) && (*in <= 0x7A)) ||
+       ((*in >= 0x41) && (*in <= 0x5A)) ||
+       (*in == '_')) {
        in++;
-       while ((((*in >= 0x61) && (*in <= 0x7A)) ||
-               ((*in >= 0x41) && (*in <= 0x5A)) ||
-               ((*in >= 0x30) && (*in <= 0x39)) ||
-               (*in == '_') || (*in == '-') ||
-               (*in == '.')) && (in < e))
+       while (((*in >= 0x61) && (*in <= 0x7A)) ||
+              ((*in >= 0x41) && (*in <= 0x5A)) ||
+              ((*in >= 0x30) && (*in <= 0x39)) ||
+              (*in == '_') || (*in == '-') ||
+              (*in == '.'))
            in++;
-       if (in >= e)
-           goto complex;
        if ((*in > 0) && (*in < 0x80)) {
            count = in - ctxt->input->cur;
             if ((count > XML_MAX_NAME_LENGTH) &&
@@ -3607,7 +3507,6 @@ xmlParseNCName(xmlParserCtxtPtr ctxt) {
            return(ret);
        }
     }
-complex:
     return(xmlParseNCNameComplex(ctxt));
 }
 
@@ -3645,7 +3544,7 @@ xmlParseNameAndCompare(xmlParserCtxtPtr ctxt, xmlChar const *other) {
     }
     /* failure (or end of input buffer), check with full function */
     ret = xmlParseName (ctxt);
-    /* strings coming from the dictionary direct compare possible */
+    /* strings coming from the dictionnary direct compare possible */
     if (ret == other) {
        return (const xmlChar*) 1;
     }
@@ -3986,10 +3885,8 @@ xmlParseEntityValue(xmlParserCtxtPtr ctxt, xmlChar **orig) {
         * 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
@@ -4114,11 +4011,9 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
                } else if ((ent != NULL) &&
                           (ctxt->replaceEntities != 0)) {
                    if (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY) {
-                       ++ctxt->depth;
                        rep = xmlStringDecodeEntities(ctxt, ent->content,
                                                      XML_SUBSTITUTE_REF,
                                                      0, 0, 0);
-                       --ctxt->depth;
                        if (rep != NULL) {
                            current = rep;
                            while (*current != 0) { /* non input consuming */
@@ -4154,10 +4049,8 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) {
                        (ent->content != NULL) && (ent->checked == 0)) {
                        unsigned long oldnbent = ctxt->nbentities;
 
-                       ++ctxt->depth;
                        rep = xmlStringDecodeEntities(ctxt, ent->content,
                                                  XML_SUBSTITUTE_REF, 0, 0, 0);
-                       --ctxt->depth;
 
                        ent->checked = (ctxt->nbentities - oldnbent + 1) * 2;
                        if (rep != NULL) {
@@ -5182,7 +5075,7 @@ xmlParsePITarget(xmlParserCtxtPtr ctxt) {
     }
     if ((name != NULL) && (xmlStrchr(name, ':') != NULL)) {
        xmlNsErr(ctxt, XML_NS_ERR_COLON,
-                "colons are forbidden from PI names '%s'\n", name, NULL, NULL);
+                "colon are forbidden from PI names '%s'\n", name, NULL, NULL);
     }
     return(name);
 }
@@ -5451,7 +5344,7 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
        }
        if (xmlStrchr(name, ':') != NULL) {
            xmlNsErr(ctxt, XML_NS_ERR_COLON,
-                    "colons are forbidden from notation names '%s'\n",
+                    "colon are forbidden from notation names '%s'\n",
                     name, NULL, NULL);
        }
        SKIP_BLANKS;
@@ -5527,7 +5420,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
            skipped = SKIP_BLANKS;
            if (skipped == 0) {
                xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
-                              "Space required after '%%'\n");
+                              "Space required after '%'\n");
            }
            isParameter = 1;
        }
@@ -5540,7 +5433,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
        }
        if (xmlStrchr(name, ':') != NULL) {
            xmlNsErr(ctxt, XML_NS_ERR_COLON,
-                    "colons are forbidden from entities names '%s'\n",
+                    "colon are forbidden from entities names '%s'\n",
                     name, NULL, NULL);
        }
         skipped = SKIP_BLANKS;
@@ -5710,7 +5603,6 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
        if (RAW != '>') {
            xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_NOT_FINISHED,
                    "xmlParseEntityDecl: entity %s not terminated\n", name);
-           xmlHaltParser(ctxt);
        } else {
            if (input != ctxt->input) {
                xmlFatalErrMsg(ctxt, XML_ERR_ENTITY_BOUNDARY,
@@ -6712,7 +6604,6 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
        if (!IS_BLANK_CH(CUR)) {
            xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED,
                           "Space required after 'ELEMENT'\n");
-           return(-1);
        }
         SKIP_BLANKS;
         name = xmlParseName(ctxt);
@@ -6823,8 +6714,6 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
        SKIP_BLANKS;
        if (RAW != '[') {
            xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);
-           xmlHaltParser(ctxt);
-           return;
        } else {
            if (ctxt->input->id != id) {
                xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
@@ -6864,7 +6753,6 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
 
            if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
                xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL);
-               xmlHaltParser(ctxt);
                break;
            }
        }
@@ -6886,8 +6774,6 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
        SKIP_BLANKS;
        if (RAW != '[') {
            xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID, NULL);
-           xmlHaltParser(ctxt);
-           return;
        } else {
            if (ctxt->input->id != id) {
                xmlValidityError(ctxt, XML_ERR_ENTITY_BOUNDARY,
@@ -6943,8 +6829,6 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
 
     } else {
        xmlFatalErr(ctxt, XML_ERR_CONDSEC_INVALID_KEYWORD, NULL);
-       xmlHaltParser(ctxt);
-       return;
     }
 
     if (RAW == 0)
@@ -6958,9 +6842,7 @@ xmlParseConditionalSections(xmlParserCtxtPtr ctxt) {
        "All markup of the conditional section is not in the same entity\n",
                                 NULL, NULL);
        }
-       if ((ctxt-> instate != XML_PARSER_EOF) &&
-           ((ctxt->input->cur + 3) <= ctxt->input->end))
-           SKIP(3);
+        SKIP(3);
     }
 }
 
@@ -7015,14 +6897,6 @@ xmlParseMarkupDecl(xmlParserCtxtPtr ctxt) {
            xmlParsePI(ctxt);
        }
     }
-
-    /*
-     * detect requirement to exit there and act accordingly
-     * and avoid having instate overriden later on
-     */
-    if (ctxt->instate == XML_PARSER_EOF)
-        return;
-
     /*
      * This is only for internal subset. On external entities,
      * the replacement is done before parsing stage
@@ -7154,7 +7028,7 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID,
            /*
             * The XML REC instructs us to stop parsing right here
             */
-           xmlHaltParser(ctxt);
+           ctxt->instate = XML_PARSER_EOF;
            return;
        }
     }
@@ -7306,8 +7180,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
      * far more secure as the parser will only process data coming from
      * the document entity by default.
      */
-    if (((ent->checked == 0) ||
-         ((ent->children == NULL) && (ctxt->options & XML_PARSE_NOENT))) &&
+    if ((ent->checked == 0) &&
         ((ent->etype != XML_EXTERNAL_GENERAL_PARSED_ENTITY) ||
          (ctxt->options & (XML_PARSE_NOENT | XML_PARSE_DTDVALID)))) {
        unsigned long oldnbent = ctxt->nbentities;
@@ -7413,7 +7286,6 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
                   (ret != XML_WAR_UNDECLARED_ENTITY)) {
            xmlFatalErrMsgStr(ctxt, XML_ERR_UNDECLARED_ENTITY,
                     "Entity '%s' failed to parse\n", ent->name);
-           xmlParserEntityCheck(ctxt, 0, ent, 0);
        } else if (list != NULL) {
            xmlFreeNodeList(list);
            list = NULL;
@@ -7520,7 +7392,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
                /*
                 * We are copying here, make sure there is no abuse
                 */
-               ctxt->sizeentcopy += ent->length + 5;
+               ctxt->sizeentcopy += ent->length;
                if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
                    return;
 
@@ -7568,7 +7440,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
                /*
                 * We are copying here, make sure there is no abuse
                 */
-               ctxt->sizeentcopy += ent->length + 5;
+               ctxt->sizeentcopy += ent->length;
                if (xmlParserEntityCheck(ctxt, 0, ent, ctxt->sizeentcopy))
                    return;
 
@@ -7754,7 +7626,6 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
                ctxt->sax->reference(ctxt->userData, name);
            }
        }
-       xmlParserEntityCheck(ctxt, 0, ent, 0);
        ctxt->valid = 0;
     }
 
@@ -7787,8 +7658,8 @@ xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
     else if ((ctxt->instate == XML_PARSER_ATTRIBUTE_VALUE) &&
             (ent != NULL) && 
             (ent->etype != XML_INTERNAL_PREDEFINED_ENTITY)) {
-       if (((ent->checked & 1) || (ent->checked == 0)) &&
-            (ent->content != NULL) && (xmlStrchr(ent->content, '<'))) {
+       if ((ent->checked & 1) || ((ent->checked == 0) &&
+            (ent->content != NULL) &&(xmlStrchr(ent->content, '<')))) {
            xmlFatalErrMsgStr(ctxt, XML_ERR_LT_IN_ATTRIBUTE,
        "'<' in entity '%s' is not allowed in attributes values\n", name);
         }
@@ -7882,7 +7753,7 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {
 
 
     /*
-     * Predefined entities override any extra definition
+     * Predefined entites override any extra definition
      */
     if ((ctxt->options & XML_PARSE_OLDSAX) == 0) {
         ent = xmlGetPredefinedEntity(name);
@@ -7948,7 +7819,6 @@ xmlParseStringEntityRef(xmlParserCtxtPtr ctxt, const xmlChar ** str) {
                          "Entity '%s' not defined\n",
                          name);
        }
-       xmlParserEntityCheck(ctxt, 0, ent, 0);
        /* TODO ? check regressions ctxt->valid = 0; */
     }
 
@@ -8108,7 +7978,6 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
                          name, NULL);
            ctxt->valid = 0;
        }
-       xmlParserEntityCheck(ctxt, 0, NULL, 0);
     } else {
        /*
         * Internal checking in case the entity quest barfed
@@ -8141,7 +8010,7 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
                     * The XML REC instructs us to stop parsing
                     * right here
                     */
-                   xmlHaltParser(ctxt);
+                   ctxt->instate = XML_PARSER_EOF;
                    return;
                }
            }
@@ -8348,7 +8217,6 @@ xmlParseStringPEReference(xmlParserCtxtPtr ctxt, const xmlChar **str) {
                          name, NULL);
            ctxt->valid = 0;
        }
-       xmlParserEntityCheck(ctxt, 0, NULL, 0);
     } else {
        /*
         * Internal checking in case the entity quest barfed
@@ -8496,7 +8364,6 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) {
      */
     if (RAW != '>') {
        xmlFatalErr(ctxt, XML_ERR_DOCTYPE_NOT_FINISHED, NULL);
-       return;
     }
     NEXT;
 }
@@ -8847,7 +8714,7 @@ xmlParseEndTag(xmlParserCtxtPtr ctxt) {
  * @prefix:  the prefix to lookup
  *
  * Lookup the namespace name for the @prefix (which ca be NULL)
- * The prefix must come from the @ctxt->dict dictionary
+ * The prefix must come from the @ctxt->dict dictionnary
  *
  * Returns the namespace name or NULL if not bound
  */
@@ -9039,12 +8906,9 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
     xmlChar limit = 0;
     const xmlChar *in = NULL, *start, *end, *last;
     xmlChar *ret = NULL;
-    int line, col;
 
     GROW;
     in = (xmlChar *) CUR_PTR;
-    line = ctxt->input->line;
-    col = ctxt->input->col;
     if (*in != '"' && *in != '\'') {
         xmlFatalErr(ctxt, XML_ERR_ATTRIBUTE_NOT_STARTED, NULL);
         return (NULL);
@@ -9057,7 +8921,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
      * pure ASCII.
      */
     limit = *in++;
-    col++;
     end = ctxt->input->end;
     start = in;
     if (in >= end) {
@@ -9077,11 +8940,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        while ((in < end) && (*in != limit) &&
               ((*in == 0x20) || (*in == 0x9) ||
                (*in == 0xA) || (*in == 0xD))) {
-           if (*in == 0xA) {
-               line++; col = 1;
-           } else {
-               col++;
-           }
            in++;
            start = in;
            if (in >= end) {
@@ -9105,7 +8963,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        }
        while ((in < end) && (*in != limit) && (*in >= 0x20) &&
               (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
-           col++;
            if ((*in++ == 0x20) && (*in == 0x20)) break;
            if (in >= end) {
                const xmlChar *oldbase = ctxt->input->base;
@@ -9134,11 +8991,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        while ((in < end) && (*in != limit) &&
               ((*in == 0x20) || (*in == 0x9) ||
                (*in == 0xA) || (*in == 0xD))) {
-           if (*in == 0xA) {
-               line++, col = 1;
-           } else {
-               col++;
-           }
            in++;
            if (in >= end) {
                const xmlChar *oldbase = ctxt->input->base;
@@ -9171,7 +9023,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        while ((in < end) && (*in != limit) && (*in >= 0x20) &&
               (*in <= 0x7f) && (*in != '&') && (*in != '<')) {
            in++;
-           col++;
            if (in >= end) {
                const xmlChar *oldbase = ctxt->input->base;
                GROW;
@@ -9201,7 +9052,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
        if (*in != limit) goto need_complex;
     }
     in++;
-    col++;
     if (len != NULL) {
         *len = last - start;
         ret = (xmlChar *) start;
@@ -9210,8 +9060,6 @@ xmlParseAttValueInternal(xmlParserCtxtPtr ctxt, int *len, int *alloc,
         ret = xmlStrndup(start, last - start);
     }
     CUR_PTR = in;
-    ctxt->input->line = line;
-    ctxt->input->col = col;
     if (alloc) *alloc = 0;
     return ret;
 need_complex:
@@ -9377,7 +9225,7 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref,
     const xmlChar **atts = ctxt->atts;
     int maxatts = ctxt->maxatts;
     int nratts, nbatts, nbdef;
-    int i, j, nbNs, attval, oldline, oldcol, inputNr;
+    int i, j, nbNs, attval, oldline, oldcol;
     const xmlChar *base;
     unsigned long cur;
     int nsNr = ctxt->nsNr;
@@ -9396,7 +9244,6 @@ reparse:
     SHRINK;
     base = ctxt->input->base;
     cur = ctxt->input->cur - ctxt->input->base;
-    inputNr = ctxt->inputNr;
     oldline = ctxt->input->line;
     oldcol = ctxt->input->col;
     nbatts = 0;
@@ -9422,8 +9269,7 @@ reparse:
      */
     SKIP_BLANKS;
     GROW;
-    if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
-        goto base_changed;
+    if (ctxt->input->base != base) goto base_changed;
 
     while (((RAW != '>') &&
           ((RAW != '/') || (NXT(1) != '>')) &&
@@ -9434,7 +9280,7 @@ reparse:
 
        attname = xmlParseAttribute2(ctxt, prefix, localname,
                                     &aprefix, &attvalue, &len, &alloc);
-       if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr)) {
+       if (ctxt->input->base != base) {
            if ((attvalue != NULL) && (alloc != 0))
                xmlFree(attvalue);
            attvalue = NULL;
@@ -9446,12 +9292,6 @@ reparse:
                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) {
@@ -9494,20 +9334,8 @@ reparse:
                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;
-               }
+               if (alloc != 0) xmlFree(attvalue);
                SKIP_BLANKS;
-               if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
-                   goto base_changed;
                continue;
            }
             if (aprefix == ctxt->str_xmlns) {
@@ -9579,20 +9407,9 @@ skip_default_ns:
                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;
-               }
+               if (alloc != 0) xmlFree(attvalue);
                SKIP_BLANKS;
-               if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
-                   goto base_changed;
+               if (ctxt->input->base != base) goto base_changed;
                continue;
            }
 
@@ -9629,8 +9446,7 @@ failed:
        GROW
         if (ctxt->instate == XML_PARSER_EOF)
             break;
-       if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
-           goto base_changed;
+       if (ctxt->input->base != base) goto base_changed;
        if ((RAW == '>') || (((RAW == '/') && (NXT(1) == '>'))))
            break;
        if (!IS_BLANK_CH(RAW)) {
@@ -9646,8 +9462,7 @@ failed:
            break;
        }
         GROW;
-       if ((ctxt->input->base != base) || (inputNr != ctxt->inputNr))
-           goto base_changed;
+       if (ctxt->input->base != base) goto base_changed;
     }
 
     /*
@@ -9814,17 +9629,6 @@ base_changed:
            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;
@@ -9853,7 +9657,6 @@ static void
 xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar *prefix,
                 const xmlChar *URI, int line, int nsNr, int tlen) {
     const xmlChar *name;
-    size_t curLength;
 
     GROW;
     if ((RAW != '<') || (NXT(1) != '/')) {
@@ -9862,17 +9665,12 @@ xmlParseEndTag2(xmlParserCtxtPtr ctxt, const xmlChar *prefix,
     }
     SKIP(2);
 
-    curLength = ctxt->input->end - ctxt->input->cur;
-    if ((tlen > 0) && (curLength >= (size_t)tlen) &&
-        (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) {
-        if ((curLength >= (size_t)(tlen + 1)) &&
-           (ctxt->input->cur[tlen] == '>')) {
+    if ((tlen > 0) && (xmlStrncmp(ctxt->input->cur, ctxt->name, tlen) == 0)) {
+        if (ctxt->input->cur[tlen] == '>') {
            ctxt->input->cur += tlen + 1;
-           ctxt->input->col += tlen + 1;
            goto done;
        }
        ctxt->input->cur += tlen;
-       ctxt->input->col += tlen;
        name = (xmlChar*)1;
     } else {
        if (prefix == NULL)
@@ -10110,7 +9908,7 @@ xmlParseContent(xmlParserCtxtPtr ctxt) {
        if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
            xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
                        "detected an error in element content\n");
-           xmlHaltParser(ctxt);
+           ctxt->instate = XML_PARSER_EOF;
             break;
        }
     }
@@ -10145,7 +9943,7 @@ xmlParseElement(xmlParserCtxtPtr ctxt) {
        xmlFatalErrMsgInt(ctxt, XML_ERR_INTERNAL_ERROR,
                 "Excessive depth in document: %d use XML_PARSE_HUGE option\n",
                          xmlParserMaxDepth);
-       xmlHaltParser(ctxt);
+       ctxt->instate = XML_PARSER_EOF;
        return;
     }
 
@@ -10497,8 +10295,6 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
            encoding = xmlParseEncName(ctxt);
            if (RAW != '"') {
                xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);
-               xmlFree((xmlChar *) encoding);
-               return(NULL);
            } else
                NEXT;
        } else if (RAW == '\''){
@@ -10506,8 +10302,6 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
            encoding = xmlParseEncName(ctxt);
            if (RAW != '\'') {
                xmlFatalErr(ctxt, XML_ERR_STRING_NOT_CLOSED, NULL);
-               xmlFree((xmlChar *) encoding);
-               return(NULL);
            } else
                NEXT;
        } else {
@@ -10517,10 +10311,8 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
         /*
          * Non standard parsing, allowing the user to ignore encoding
          */
-        if (ctxt->options & XML_PARSE_IGNORE_ENC) {
-           xmlFree((xmlChar *) encoding);
-            return(NULL);
-       }
+        if (ctxt->options & XML_PARSE_IGNORE_ENC)
+            return(encoding);
 
        /*
         * UTF-16 encoding stwich has already taken place at this stage,
@@ -10564,11 +10356,7 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
 
             handler = xmlFindCharEncodingHandler((const char *) encoding);
            if (handler != NULL) {
-               if (xmlSwitchToEncoding(ctxt, handler) < 0) {
-                   /* failed to convert */
-                   ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
-                   return(NULL);
-               }
+               xmlSwitchToEncoding(ctxt, handler);
            } else {
                xmlFatalErrMsgStr(ctxt, XML_ERR_UNSUPPORTED_ENCODING,
                        "Unsupported encoding %s\n", encoding);
@@ -10737,8 +10525,7 @@ xmlParseXMLDecl(xmlParserCtxtPtr ctxt) {
        xmlFatalErrMsg(ctxt, XML_ERR_SPACE_REQUIRED, "Blank needed here\n");
     }
     xmlParseEncodingDecl(ctxt);
-    if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
-         (ctxt->instate == XML_PARSER_EOF)) {
+    if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
        /*
         * The XML REC instructs us to stop parsing right here
         */
@@ -10862,7 +10649,6 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
 
     if (CUR == 0) {
        xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
-       return(-1);
     }
 
     /*
@@ -10880,8 +10666,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
         * Note that we will switch encoding on the fly.
         */
        xmlParseXMLDecl(ctxt);
-       if ((ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) ||
-           (ctxt->instate == XML_PARSER_EOF)) {
+       if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) {
            /*
             * The XML REC instructs us to stop parsing right here
             */
@@ -10896,10 +10681,6 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
         ctxt->sax->startDocument(ctxt->userData);
     if (ctxt->instate == XML_PARSER_EOF)
        return(-1);
-    if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&
-        (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {
-       ctxt->myDoc->compression = ctxt->input->buf->compressed;
-    }
 
     /*
      * The Misc part of the Prolog
@@ -11250,9 +11031,8 @@ xmlParseGetLasts(xmlParserCtxtPtr ctxt, const xmlChar **lastlt,
 }
 /**
  * xmlCheckCdataPush:
- * @cur: pointer to the block of characters
+ * @cur: pointer to the bock of characters
  * @len: length of the block in bytes
- * @complete: 1 if complete CDATA block is passed in, 0 if partial block
  *
  * Check that the block of characters is okay as SCdata content [20]
  *
@@ -11260,7 +11040,7 @@ xmlParseGetLasts(xmlParserCtxtPtr ctxt, const xmlChar **lastlt,
  *         UTF-8 error occured otherwise
  */
 static int
-xmlCheckCdataPush(const xmlChar *utf, int len, int complete) {
+xmlCheckCdataPush(const xmlChar *utf, int len) {
     int ix;
     unsigned char c;
     int codepoint;
@@ -11278,7 +11058,7 @@ xmlCheckCdataPush(const xmlChar *utf, int len, int complete) {
            else
                return(-ix);
        } else if ((c & 0xe0) == 0xc0) {/* 2-byte code, starts with 110 */
-           if (ix + 2 > len) return(complete ? -ix : ix);
+           if (ix + 2 > len) return(ix);
            if ((utf[ix+1] & 0xc0 ) != 0x80)
                return(-ix);
            codepoint = (utf[ix] & 0x1f) << 6;
@@ -11287,7 +11067,7 @@ xmlCheckCdataPush(const xmlChar *utf, int len, int complete) {
                return(-ix);
            ix += 2;
        } else if ((c & 0xf0) == 0xe0) {/* 3-byte code, starts with 1110 */
-           if (ix + 3 > len) return(complete ? -ix : ix);
+           if (ix + 3 > len) return(ix);
            if (((utf[ix+1] & 0xc0) != 0x80) ||
                ((utf[ix+2] & 0xc0) != 0x80))
                    return(-ix);
@@ -11298,7 +11078,7 @@ xmlCheckCdataPush(const xmlChar *utf, int len, int complete) {
                return(-ix);
            ix += 3;
        } else if ((c & 0xf8) == 0xf0) {/* 4-byte code, starts with 11110 */
-           if (ix + 4 > len) return(complete ? -ix : ix);
+           if (ix + 4 > len) return(ix);
            if (((utf[ix+1] & 0xc0) != 0x80) ||
                ((utf[ix+2] & 0xc0) != 0x80) ||
                ((utf[ix+3] & 0xc0) != 0x80))
@@ -11476,7 +11256,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                        ctxt->sax->setDocumentLocator(ctxt->userData,
                                                      &xmlDefaultSAXLocator);
                    xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
-                   xmlHaltParser(ctxt);
+                   ctxt->instate = XML_PARSER_EOF;
 #ifdef DEBUG_PUSH
                    xmlGenericError(xmlGenericErrorContext,
                            "PP: entering EOF\n");
@@ -11509,7 +11289,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                             * The XML REC instructs us to stop parsing right
                             * here
                             */
-                           xmlHaltParser(ctxt);
+                           ctxt->instate = XML_PARSER_EOF;
                            return(0);
                        }
                        ctxt->standalone = ctxt->input->standalone;
@@ -11565,7 +11345,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                cur = ctxt->input->cur[0];
                if (cur != '<') {
                    xmlFatalErr(ctxt, XML_ERR_DOCUMENT_EMPTY, NULL);
-                   xmlHaltParser(ctxt);
+                   ctxt->instate = XML_PARSER_EOF;
                    if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
                        ctxt->sax->endDocument(ctxt->userData);
                    goto done;
@@ -11597,7 +11377,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                    goto done;
                if (name == NULL) {
                    spacePop(ctxt);
-                   xmlHaltParser(ctxt);
+                   ctxt->instate = XML_PARSER_EOF;
                    if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
                        ctxt->sax->endDocument(ctxt->userData);
                    goto done;
@@ -11764,7 +11544,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
                    xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
                                "detected an error in element content\n");
-                   xmlHaltParser(ctxt);
+                   ctxt->instate = XML_PARSER_EOF;
                    break;
                }
                break;
@@ -11813,7 +11593,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                        int tmp;
 
                        tmp = xmlCheckCdataPush(ctxt->input->cur,
-                                               XML_PARSER_BIG_BUFFER_SIZE, 0);
+                                               XML_PARSER_BIG_BUFFER_SIZE);
                        if (tmp < 0) {
                            tmp = -tmp;
                            ctxt->input->cur += tmp;
@@ -11836,7 +11616,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                } else {
                    int tmp;
 
-                   tmp = xmlCheckCdataPush(ctxt->input->cur, base, 1);
+                   tmp = xmlCheckCdataPush(ctxt->input->cur, base);
                    if ((tmp < 0) || (tmp != base)) {
                        tmp = -tmp;
                        ctxt->input->cur += tmp;
@@ -12085,7 +11865,7 @@ xmlParseTryOrFinish(xmlParserCtxtPtr ctxt, int terminate) {
                    goto done;
                } else {
                    xmlFatalErr(ctxt, XML_ERR_DOCUMENT_END, NULL);
-                   xmlHaltParser(ctxt);
+                   ctxt->instate = XML_PARSER_EOF;
 #ifdef DEBUG_PUSH
                    xmlGenericError(xmlGenericErrorContext,
                            "PP: entering EOF\n");
@@ -12449,7 +12229,7 @@ xmldecl_done:
        res = xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
        if (res < 0) {
            ctxt->errNo = XML_PARSER_EOF;
-           xmlHaltParser(ctxt);
+           ctxt->disableSAX = 1;
            return (XML_PARSER_EOF);
        }
         xmlBufSetInputBaseCur(ctxt->input->buf->buffer, ctxt->input, base, cur);
@@ -12503,7 +12283,7 @@ xmldecl_done:
          ((ctxt->input->cur - ctxt->input->base) > XML_MAX_LOOKUP_LIMIT)) &&
         ((ctxt->options & XML_PARSE_HUGE) == 0)) {
         xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "Huge input lookup");
-        xmlHaltParser(ctxt);
+        ctxt->instate = XML_PARSER_EOF;
     }
     if ((ctxt->errNo != XML_ERR_OK) && (ctxt->disableSAX == 1))
         return(ctxt->errNo);
@@ -12691,47 +12471,25 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
 #endif /* LIBXML_PUSH_ENABLED */
 
 /**
- * xmlHaltParser:
+ * xmlStopParser:
  * @ctxt:  an XML parser context
  *
- * Blocks further parser processing don't override error
- * for internal use
+ * Blocks further parser processing
  */
-static void
-xmlHaltParser(xmlParserCtxtPtr ctxt) {
+void
+xmlStopParser(xmlParserCtxtPtr ctxt) {
     if (ctxt == NULL)
         return;
     ctxt->instate = XML_PARSER_EOF;
+    ctxt->errNo = XML_ERR_USER_STOP;
     ctxt->disableSAX = 1;
     if (ctxt->input != NULL) {
-        /*
-        * in case there was a specific allocation deallocate before
-        * overriding base
-        */
-        if (ctxt->input->free != NULL) {
-           ctxt->input->free((xmlChar *) ctxt->input->base);
-           ctxt->input->free = NULL;
-       }
        ctxt->input->cur = BAD_CAST"";
        ctxt->input->base = ctxt->input->cur;
     }
 }
 
 /**
- * xmlStopParser:
- * @ctxt:  an XML parser context
- *
- * Blocks further parser processing
- */
-void
-xmlStopParser(xmlParserCtxtPtr ctxt) {
-    if (ctxt == NULL)
-        return;
-    xmlHaltParser(ctxt);
-    ctxt->errNo = XML_ERR_USER_STOP;
-}
-
-/**
  * xmlCreateIOParserCtxt:
  * @sax:  a SAX handler
  * @user_data:  The user data returned on SAX callbacks
@@ -12833,9 +12591,6 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input,
        return(NULL);
     }
 
-    /* We are loading a DTD */
-    ctxt->options |= XML_PARSE_DTDLOAD;
-
     /*
      * Set-up the SAX context
      */
@@ -12963,9 +12718,6 @@ xmlSAXParseDTD(xmlSAXHandlerPtr sax, const xmlChar *ExternalID,
        return(NULL);
     }
 
-    /* We are loading a DTD */
-    ctxt->options |= XML_PARSE_DTDLOAD;
-
     /*
      * Set-up the SAX context
      */
@@ -13475,7 +13227,7 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
     /*
      * Also record the size of the entity parsed
      */
-    if (ctxt->input != NULL && oldctxt != NULL) {
+    if (ctxt->input != NULL) {
        oldctxt->sizeentities += ctxt->input->consumed;
        oldctxt->sizeentities += (ctxt->input->cur - ctxt->input->base);
     }
@@ -13487,11 +13239,9 @@ xmlParseExternalEntityPrivate(xmlDocPtr doc, xmlParserCtxtPtr oldctxt,
 
     if (sax != NULL)
        ctxt->sax = oldsax;
-    if (oldctxt != NULL) {
-        oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
-        oldctxt->node_seq.length = ctxt->node_seq.length;
-        oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
-    }
+    oldctxt->node_seq.maximum = ctxt->node_seq.maximum;
+    oldctxt->node_seq.length = ctxt->node_seq.length;
+    oldctxt->node_seq.buffer = ctxt->node_seq.buffer;
     ctxt->node_seq.maximum = 0;
     ctxt->node_seq.length = 0;
     ctxt->node_seq.buffer = NULL;
@@ -13857,7 +13607,7 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
            xmlFree((xmlChar *) ctxt->encoding);
         ctxt->encoding = xmlStrdup((const xmlChar *) doc->encoding);
 
-        hdlr = xmlFindCharEncodingHandler((const char *) doc->encoding);
+        hdlr = xmlFindCharEncodingHandler(doc->encoding);
         if (hdlr != NULL) {
             xmlSwitchToEncoding(ctxt, hdlr);
        } else {
@@ -13868,8 +13618,6 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
     xmlCtxtUseOptionsInternal(ctxt, options, NULL);
     xmlDetectSAX2(ctxt);
     ctxt->myDoc = doc;
-    /* parsing in context, i.e. as within existing content */
-    ctxt->instate = XML_PARSER_CONTENT;
 
     fake = xmlNewComment(NULL);
     if (fake == NULL) {
@@ -13905,6 +13653,7 @@ xmlParseInNodeContext(xmlNodePtr node, const char *data, int datalen,
            }
            cur = cur->parent;
        }
+       ctxt->instate = XML_PARSER_CONTENT;
     }
 
     if ((ctxt->validate) || (ctxt->replaceEntities != 0)) {
@@ -15014,8 +14763,8 @@ xmlCleanupParser(void) {
     xmlSchemaCleanupTypes();
     xmlRelaxNGCleanupTypes();
 #endif
-    xmlResetLastError();
     xmlCleanupGlobals();
+    xmlResetLastError();
     xmlCleanupThreads(); /* must be last if called not from the main thread */
     xmlCleanupMemory();
     xmlParserInitialized = 0;
@@ -15031,7 +14780,7 @@ xmlCleanupParser(void) {
  * DICT_FREE:
  * @str:  a string
  *
- * Free a string if it is not owned by the "dict" dictionary in the
+ * Free a string if it is not owned by the "dict" dictionnary in the
  * current scope
  */
 #define DICT_FREE(str)                                         \
@@ -15464,7 +15213,6 @@ xmlReadDoc(const xmlChar * cur, const char *URL, const char *encoding, int optio
 
     if (cur == NULL)
         return (NULL);
-    xmlInitParser();
 
     ctxt = xmlCreateDocParserCtxt(cur);
     if (ctxt == NULL)
@@ -15487,7 +15235,6 @@ xmlReadFile(const char *filename, const char *encoding, int options)
 {
     xmlParserCtxtPtr ctxt;
 
-    xmlInitParser();
     ctxt = xmlCreateURLParserCtxt(filename, options);
     if (ctxt == NULL)
         return (NULL);
@@ -15511,7 +15258,6 @@ xmlReadMemory(const char *buffer, int size, const char *URL, const char *encodin
 {
     xmlParserCtxtPtr ctxt;
 
-    xmlInitParser();
     ctxt = xmlCreateMemoryParserCtxt(buffer, size);
     if (ctxt == NULL)
         return (NULL);
@@ -15540,7 +15286,6 @@ xmlReadFd(int fd, const char *URL, const char *encoding, int options)
 
     if (fd < 0)
         return (NULL);
-    xmlInitParser();
 
     input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);
     if (input == NULL)
@@ -15584,7 +15329,6 @@ xmlReadIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
 
     if (ioread == NULL)
         return (NULL);
-    xmlInitParser();
 
     input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
                                          XML_CHAR_ENCODING_NONE);
@@ -15631,7 +15375,6 @@ xmlCtxtReadDoc(xmlParserCtxtPtr ctxt, const xmlChar * cur,
         return (NULL);
     if (ctxt == NULL)
         return (NULL);
-    xmlInitParser();
 
     xmlCtxtReset(ctxt);
 
@@ -15665,7 +15408,6 @@ xmlCtxtReadFile(xmlParserCtxtPtr ctxt, const char *filename,
         return (NULL);
     if (ctxt == NULL)
         return (NULL);
-    xmlInitParser();
 
     xmlCtxtReset(ctxt);
 
@@ -15702,7 +15444,6 @@ xmlCtxtReadMemory(xmlParserCtxtPtr ctxt, const char *buffer, int size,
         return (NULL);
     if (buffer == NULL)
         return (NULL);
-    xmlInitParser();
 
     xmlCtxtReset(ctxt);
 
@@ -15747,7 +15488,6 @@ xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
         return (NULL);
     if (ctxt == NULL)
         return (NULL);
-    xmlInitParser();
 
     xmlCtxtReset(ctxt);
 
@@ -15793,7 +15533,6 @@ xmlCtxtReadIO(xmlParserCtxtPtr ctxt, xmlInputReadCallback ioread,
         return (NULL);
     if (ctxt == NULL)
         return (NULL);
-    xmlInitParser();
 
     xmlCtxtReset(ctxt);