Merge branch 'tizen_base' into tizen
[platform/upstream/libxml2.git] / valid.c
diff --git a/valid.c b/valid.c
index 409aa81..a64b96b 100644 (file)
--- a/valid.c
+++ b/valid.c
@@ -93,7 +93,7 @@ xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra)
  *
  * Handle a validation error
  */
-static void
+static void LIBXML_ATTR_FORMAT(3,0)
 xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error,
             const char *msg, const char *extra)
 {
@@ -137,7 +137,7 @@ xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error,
  *
  * Handle a validation error, provide contextual informations
  */
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlErrValidNode(xmlValidCtxtPtr ctxt,
                 xmlNodePtr node, xmlParserErrors error,
                 const char *msg, const xmlChar * str1,
@@ -163,7 +163,7 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt,
     __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
                     XML_ERR_ERROR, NULL, 0,
                     (const char *) str1,
-                    (const char *) str1,
+                    (const char *) str2,
                     (const char *) str3, 0, 0, msg, str1, str2, str3);
 }
 #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
@@ -180,7 +180,7 @@ xmlErrValidNode(xmlValidCtxtPtr ctxt,
  *
  * Handle a validation error, provide contextual informations
  */
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlErrValidNodeNr(xmlValidCtxtPtr ctxt,
                 xmlNodePtr node, xmlParserErrors error,
                 const char *msg, const xmlChar * str1,
@@ -221,7 +221,7 @@ xmlErrValidNodeNr(xmlValidCtxtPtr ctxt,
  *
  * Handle a validation error, provide contextual information
  */
-static void
+static void LIBXML_ATTR_FORMAT(4,0)
 xmlErrValidWarning(xmlValidCtxtPtr ctxt,
                 xmlNodePtr node, xmlParserErrors error,
                 const char *msg, const xmlChar * str1,
@@ -247,7 +247,7 @@ xmlErrValidWarning(xmlValidCtxtPtr ctxt,
     __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,
                     XML_ERR_WARNING, NULL, 0,
                     (const char *) str1,
-                    (const char *) str1,
+                    (const char *) str2,
                     (const char *) str3, 0, 0, msg, str1, str2, str3);
 }
 
@@ -1172,29 +1172,33 @@ xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob)
            xmlBufferWriteCHAR(buf, content->name);
            break;
        case XML_ELEMENT_CONTENT_SEQ:
-           if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
-               (content->c1->type == XML_ELEMENT_CONTENT_SEQ))
+           if ((content->c1 != NULL) &&
+               ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
+                (content->c1->type == XML_ELEMENT_CONTENT_SEQ)))
                xmlDumpElementContent(buf, content->c1, 1);
            else
                xmlDumpElementContent(buf, content->c1, 0);
             xmlBufferWriteChar(buf, " , ");
-           if ((content->c2->type == XML_ELEMENT_CONTENT_OR) ||
-               ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) &&
-                (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)))
+           if ((content->c2 != NULL) &&
+               ((content->c2->type == XML_ELEMENT_CONTENT_OR) ||
+                ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) &&
+                 (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))))
                xmlDumpElementContent(buf, content->c2, 1);
            else
                xmlDumpElementContent(buf, content->c2, 0);
            break;
        case XML_ELEMENT_CONTENT_OR:
-           if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
-               (content->c1->type == XML_ELEMENT_CONTENT_SEQ))
+           if ((content->c1 != NULL) &&
+               ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
+                (content->c1->type == XML_ELEMENT_CONTENT_SEQ)))
                xmlDumpElementContent(buf, content->c1, 1);
            else
                xmlDumpElementContent(buf, content->c1, 0);
             xmlBufferWriteChar(buf, " | ");
-           if ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) ||
-               ((content->c2->type == XML_ELEMENT_CONTENT_OR) &&
-                (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)))
+           if ((content->c2 != NULL) &&
+               ((content->c2->type == XML_ELEMENT_CONTENT_SEQ) ||
+                ((content->c2->type == XML_ELEMENT_CONTENT_OR) &&
+                 (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE))))
                xmlDumpElementContent(buf, content->c2, 1);
            else
                xmlDumpElementContent(buf, content->c2, 0);
@@ -1262,22 +1266,23 @@ xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int
         case XML_ELEMENT_CONTENT_PCDATA:
             strcat(buf, "#PCDATA");
            break;
-       case XML_ELEMENT_CONTENT_ELEMENT:
+       case XML_ELEMENT_CONTENT_ELEMENT: {
+            int qnameLen = xmlStrlen(content->name);
+
+           if (content->prefix != NULL)
+                qnameLen += xmlStrlen(content->prefix) + 1;
+           if (size - len < qnameLen + 10) {
+               strcat(buf, " ...");
+               return;
+           }
            if (content->prefix != NULL) {
-               if (size - len < xmlStrlen(content->prefix) + 10) {
-                   strcat(buf, " ...");
-                   return;
-               }
                strcat(buf, (char *) content->prefix);
                strcat(buf, ":");
            }
-           if (size - len < xmlStrlen(content->name) + 10) {
-               strcat(buf, " ...");
-               return;
-           }
            if (content->name != NULL)
                strcat(buf, (char *) content->name);
            break;
+        }
        case XML_ELEMENT_CONTENT_SEQ:
            if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
                (content->c1->type == XML_ELEMENT_CONTENT_SEQ))
@@ -1319,6 +1324,7 @@ xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int
                xmlSnprintfElementContent(buf, size, content->c2, 0);
            break;
     }
+    if (size - strlen(buf) <= 2) return;
     if (englob)
         strcat(buf, ")");
     switch (content->ocur) {
@@ -2532,7 +2538,7 @@ xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) {
  * DICT_FREE:
  * @str:  a string
  *
- * Free a string if it is not owned by the "dict" dictionnary in the
+ * Free a string if it is not owned by the "dict" dictionary in the
  * current scope
  */
 #define DICT_FREE(str)                                         \
@@ -2634,8 +2640,10 @@ xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,
        /*
         * The id is already defined in this DTD.
         */
-       xmlErrValidNode(ctxt, attr->parent, XML_DTD_ID_REDEFINED,
-                       "ID %s already defined\n", value, NULL, NULL);
+       if (ctxt != NULL) {
+           xmlErrValidNode(ctxt, attr->parent, XML_DTD_ID_REDEFINED,
+                           "ID %s already defined\n", value, NULL, NULL);
+       }
 #endif /* LIBXML_VALID_ENABLED */
        xmlFreeID(ret);
        return(NULL);
@@ -4619,6 +4627,12 @@ xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) {
        }
     }
 
+    /*
+     * Casting ns to xmlAttrPtr is wrong. We'd need separate functions
+     * xmlAddID and xmlAddRef for namespace declarations, but it makes
+     * no practical sense to use ID types anyway.
+     */
+#if 0
     /* Validity Constraint: ID uniqueness */
     if (attrDecl->atype == XML_ATTRIBUTE_ID) {
         if (xmlAddID(ctxt, doc, value, (xmlAttrPtr) ns) == NULL)
@@ -4630,6 +4644,7 @@ xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) {
         if (xmlAddRef(ctxt, doc, value, (xmlAttrPtr) ns) == NULL)
            ret = 0;
     }
+#endif
 
     /* Validity Constraint: Notation Attributes */
     if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) {
@@ -5175,6 +5190,7 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) {
             case XML_TEXT_NODE:
                if (xmlIsBlankNode(cur))
                    break;
+                /* Falls through. */
             case XML_CDATA_SECTION_NODE:
             case XML_ENTITY_REF_NODE:
                strcat(buf, "CDATA");
@@ -5723,7 +5739,7 @@ xmlValidatePushElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
        xmlElementPtr elemDecl;
 
        /*
-        * Check the new element agaisnt the content model of the new elem.
+        * Check the new element against the content model of the new elem.
         */
        if (state->elemDecl != NULL) {
            elemDecl = state->elemDecl;
@@ -5815,7 +5831,7 @@ xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) {
        xmlElementPtr elemDecl;
 
        /*
-        * Check the new element agaisnt the content model of the new elem.
+        * Check the new element against the content model of the new elem.
         */
        if (state->elemDecl != NULL) {
            elemDecl = state->elemDecl;
@@ -5889,7 +5905,7 @@ xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED,
        xmlElementPtr elemDecl;
 
        /*
-        * Check the new element agaisnt the content model of the new elem.
+        * Check the new element against the content model of the new elem.
         */
        if (state->elemDecl != NULL) {
            elemDecl = state->elemDecl;