avoid a quadratic behaviour when hitting duplicates
authorDaniel Veillard <veillard@src.gnome.org>
Sun, 27 Jul 2008 11:54:07 +0000 (11:54 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Sun, 27 Jul 2008 11:54:07 +0000 (11:54 +0000)
* libxslt/xslt.c: avoid a quadratic behaviour when hitting duplicates
  exclude-result-prefixes declarations, should fix #544906
Daniel

svn path=/trunk/; revision=1485

ChangeLog
libxslt/xslt.c

index e8c2897..1a46fa7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jul 27 13:52:10 CEST 2008 Daniel Veillard <veillard@redhat.com>
+
+       * libxslt/xslt.c: avoid a quadratic behaviour when hitting duplicates
+         exclude-result-prefixes declarations, should fix #544906
+
 Sat Jul 26 12:43:18 PST 2008 William Brack <wbrack@mmm.com.hk>
 
        *configure.in: fixed option --with-debugger with patch from
index 6f76a33..071658b 100644 (file)
@@ -141,11 +141,14 @@ xsltParseContentError(xsltStylesheetPtr style,
  *
  * Push an excluded namespace name on the stack
  *
- * Returns the new index in the stack or 0 in case of error
+ * Returns the new index in the stack or -1 if already present or
+ * in case of error
  */
 static int
 exclPrefixPush(xsltStylesheetPtr style, xmlChar * value)
 {
+    int i;
+
     if (style->exclPrefixMax == 0) {
         style->exclPrefixMax = 4;
         style->exclPrefixTab =
@@ -153,9 +156,14 @@ exclPrefixPush(xsltStylesheetPtr style, xmlChar * value)
                                    sizeof(style->exclPrefixTab[0]));
         if (style->exclPrefixTab == NULL) {
             xmlGenericError(xmlGenericErrorContext, "malloc failed !\n");
-            return (0);
+            return (-1);
         }
     }
+    /* do not push duplicates */
+    for (i = 0;i < style->exclPrefixNr;i++) {
+        if (xmlStrEqual(style->exclPrefixTab[i], value))
+           return(-1);
+    }
     if (style->exclPrefixNr >= style->exclPrefixMax) {
         style->exclPrefixMax *= 2;
         style->exclPrefixTab =
@@ -164,7 +172,7 @@ exclPrefixPush(xsltStylesheetPtr style, xmlChar * value)
                                     sizeof(style->exclPrefixTab[0]));
         if (style->exclPrefixTab == NULL) {
             xmlGenericError(xmlGenericErrorContext, "realloc failed !\n");
-            return (0);
+            return (-1);
         }
     }
     style->exclPrefixTab[style->exclPrefixNr] = value;
@@ -1704,12 +1712,13 @@ xsltParseStylesheetExcludePrefix(xsltStylesheetPtr style, xmlNodePtr cur,
                                 prefix);
                if (style != NULL) style->warnings++;
            } else {
+               if (exclPrefixPush(style, (xmlChar *) ns->href) >= 0) {
 #ifdef WITH_XSLT_DEBUG_PARSING
-               xsltGenericDebug(xsltGenericDebugContext,
-                   "exclude result prefix %s\n", prefix);
+                   xsltGenericDebug(xsltGenericDebugContext,
+                       "exclude result prefix %s\n", prefix);
 #endif
-               exclPrefixPush(style, (xmlChar *) ns->href);
-               nb++;
+                   nb++;
+               }
            }
            xmlFree(prefix);
        }