libxslt r1485 - in trunk: . libxslt



Author: veillard
Date: Sun Jul 27 11:54:07 2008
New Revision: 1485
URL: http://svn.gnome.org/viewvc/libxslt?rev=1485&view=rev

Log:
* libxslt/xslt.c: avoid a quadratic behaviour when hitting duplicates
  exclude-result-prefixes declarations, should fix #544906
Daniel


Modified:
   trunk/ChangeLog
   trunk/libxslt/xslt.c

Modified: trunk/libxslt/xslt.c
==============================================================================
--- trunk/libxslt/xslt.c	(original)
+++ trunk/libxslt/xslt.c	Sun Jul 27 11:54:07 2008
@@ -141,11 +141,14 @@
  *
  * 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 @@
                                    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 @@
                                     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 @@
 	                         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);
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]