Fix allocation bug with namespaces.
authorJames Clark <jjc@jclark.com>
Fri, 14 Apr 2000 09:28:21 +0000 (09:28 +0000)
committerJames Clark <jjc@jclark.com>
Fri, 14 Apr 2000 09:28:21 +0000 (09:28 +0000)
expat/xmlparse/xmlparse.c

index 577c6814f9a1a0b458eeca2864d82a57d0c01bd5..82e5fd665ece8b097b5e7a99d6546af4b12d44e9 100755 (executable)
@@ -1784,15 +1784,23 @@ static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc,
     return XML_ERROR_NONE;
   tagNamePtr->localPart = localPart;
   tagNamePtr->uriLen = binding->uriLen;
-  i = binding->uriLen;
-  do {
-    if (i == binding->uriAlloc) {
-      binding->uri = realloc(binding->uri, (binding->uriAlloc *= 2) * sizeof(XML_Char));
-      if (!binding->uri)
-       return XML_ERROR_NO_MEMORY;
-    }
-    binding->uri[i++] = *localPart;
-  } while (*localPart++);
+  for (i = 0; localPart[i++];)
+    ;
+  n = i + binding->uriLen;
+  if (n > binding->uriAlloc) {
+    TAG *p;
+    XML_Char *uri = malloc((n + EXPAND_SPARE) * sizeof(XML_Char));
+    if (!uri)
+      return XML_ERROR_NO_MEMORY;
+    binding->uriAlloc = n + EXPAND_SPARE;
+    memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char));
+    for (p = tagStack; p; p = p->parent)
+      if (p->name.str == binding->uri)
+       p->name.str = uri;
+    free(binding->uri);
+    binding->uri = uri;
+  }
+  memcpy(binding->uri + binding->uriLen, localPart, i * sizeof(XML_Char));
   tagNamePtr->str = binding->uri;
   return XML_ERROR_NONE;
 }