Fix generate-id() to avoid generating the same ID
authorStewart Brodie <stewart@eh.org>
Wed, 21 Nov 2012 03:11:46 +0000 (11:11 +0800)
committerDaniel Veillard <veillard@redhat.com>
Wed, 21 Nov 2012 03:11:46 +0000 (11:11 +0800)
For nodes from different documents, especially for the document
node itself which would always get "idp0" as a result.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=688171

libxslt/functions.c

index c754994..dc61994 100644 (file)
@@ -660,6 +660,7 @@ xsltFormatNumberFunction(xmlXPathParserContextPtr ctxt, int nargs)
  */
 void
 xsltGenerateIdFunction(xmlXPathParserContextPtr ctxt, int nargs){
+    static char base_address;
     xmlNodePtr cur = NULL;
     xmlXPathObjectPtr obj = NULL;
     long val;
@@ -716,7 +717,7 @@ xsltGenerateIdFunction(xmlXPathParserContextPtr ctxt, int nargs){
     if (obj)
         xmlXPathFreeObject(obj);
 
-    val = (long)((char *)cur - (char *)doc);
+    val = (long)((char *)cur - (char *)&base_address);
     if (val >= 0) {
       sprintf((char *)str, "idp%ld", val);
     } else {