]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/xml-tree.c
(no commit message)
[imagemagick] / MagickCore / xml-tree.c
index d7c1002f6c6cb1512fa147efd4dde24e19c24620..e3c8a82acfa1f231bce6c85cc2ed4ad436a3c00d 100644 (file)
@@ -458,6 +458,52 @@ static char **DestroyXMLTreeAttributes(char **attributes)
   return((char **) NULL);
 }
 
+static void DestroyXMLTreeChild(XMLTreeInfo *xml_info)
+{
+  XMLTreeInfo
+    *node,
+    *prev;
+
+  node=xml_info->child;
+  while(node != (XMLTreeInfo *) NULL)
+  {
+    prev=(XMLTreeInfo *) NULL;
+    while(node->child != (XMLTreeInfo *) NULL)
+    {
+      prev=node;
+      node=node->child;
+    }
+    (void) DestroyXMLTree(node);
+    if (prev != (XMLTreeInfo* ) NULL)
+      prev->child=(XMLTreeInfo *) NULL;
+    node=prev;
+  }
+  xml_info->child=(XMLTreeInfo *) NULL;
+}
+
+static void DestroyXMLTreeOrdered(XMLTreeInfo *xml_info)
+{
+  XMLTreeInfo
+    *node,
+    *prev;
+
+  node=xml_info->ordered;
+  while(node != (XMLTreeInfo *) NULL)
+  {
+    prev=(XMLTreeInfo *) NULL;
+    while(node->ordered != (XMLTreeInfo *) NULL)
+    {
+      prev=node;
+      node=node->ordered;
+    }
+    (void) DestroyXMLTree(node);
+    if (prev != (XMLTreeInfo* ) NULL)
+      prev->ordered=(XMLTreeInfo *) NULL;
+    node=prev;
+  }
+  xml_info->ordered=(XMLTreeInfo *) NULL;
+}
+
 static void DestroyXMLTreeRoot(XMLTreeInfo *xml_info)
 {
   char
@@ -528,10 +574,8 @@ MagickExport XMLTreeInfo *DestroyXMLTree(XMLTreeInfo *xml_info)
          (((XMLTreeRoot *) xml_info)->signature == MagickSignature));
   if (xml_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  if (xml_info->child != (XMLTreeInfo *) NULL)
-    xml_info->child=DestroyXMLTree(xml_info->child);
-  if (xml_info->ordered != (XMLTreeInfo *) NULL)
-    xml_info->ordered=DestroyXMLTree(xml_info->ordered);
+  DestroyXMLTreeChild(xml_info);
+  DestroyXMLTreeOrdered(xml_info);
   DestroyXMLTreeRoot(xml_info);
   xml_info->attributes=DestroyXMLTreeAttributes(xml_info->attributes);
   xml_info->content=DestroyString(xml_info->content);
@@ -565,7 +609,8 @@ MagickExport XMLTreeInfo *DestroyXMLTree(XMLTreeInfo *xml_info)
 %
 */
 
-static inline size_t MagickMin(const size_t x,const size_t y)
+static inline MagickSizeType MagickMin(const MagickSizeType x,
+  const MagickSizeType y)
 {
   if (x < y)
     return(x);
@@ -1474,7 +1519,8 @@ static char *ParseEntities(char *xml,char **entities,int state)
                   xml=p+offset;
                   entity=strchr(xml,';');
                 }
-              (void) CopyMagickMemory(xml+length,entity+1,strlen(entity));
+              if (entity != (char *) NULL)
+                (void) CopyMagickMemory(xml+length,entity+1,strlen(entity));
               (void) strncpy(xml,entities[i],length);
             }
         }
@@ -1517,7 +1563,7 @@ static void ParseCharacterContent(XMLTreeRoot *root,char *xml,
     return;
   xml[length]='\0';
   xml=ParseEntities(xml,root->entities,state);
-  if (*xml_info->content != '\0')
+  if ((xml_info->content != (char *) NULL) && (*xml_info->content != '\0'))
     {
       (void) ConcatenateString(&xml_info->content,xml);
       xml=DestroyString(xml);
@@ -1638,7 +1684,7 @@ static void ParseProcessingInstructions(XMLTreeRoot *root,char *xml,
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   root->processing_instructions[i][j+2]=(char *) ResizeQuantumMemory(
     root->processing_instructions[i][j+1],(size_t) (j+1),
-    sizeof(**root->processing_instructions));
+    sizeof(*root->processing_instructions));
   if (root->processing_instructions[i][j+2] == (char *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   (void) CopyMagickString(root->processing_instructions[i][j+2]+j-1,
@@ -1751,6 +1797,7 @@ static MagickBooleanType ParseInternalDoctype(XMLTreeRoot *root,char *xml,
             *xml='\0';
             i=0;
             while ((root->attributes[i] != (char **) NULL) &&
+                   (n != (char *) NULL) &&
                    (strcmp(n,root->attributes[i][0]) != 0))
               i++;
             while ((*(n=xml+strspn(xml+1,XMLWhitespace)+1) != '\0') &&
@@ -1876,7 +1923,8 @@ static void ParseOpenTag(XMLTreeRoot *root,char *tag,char **attributes)
     xml_info->tag=ConstantString(tag);
   else
     xml_info=AddChildToXMLTree(xml_info,tag,strlen(xml_info->content));
-  xml_info->attributes=attributes;
+  if (xml_info != (XMLTreeInfo *) NULL)
+    xml_info->attributes=attributes;
   root->node=xml_info;
 }
 
@@ -2449,7 +2497,7 @@ MagickPrivate XMLTreeInfo *SetXMLTreeAttribute(XMLTreeInfo *xml_info,
   j-=2;
   (void) CopyMagickMemory(xml_info->attributes[j+1]+(i/2),
     xml_info->attributes[j+1]+(i/2)+1,(size_t) (((j+2)/2)-(i/2))*
-    sizeof(*xml_info->attributes));
+    sizeof(**xml_info->attributes));
   return(xml_info);
 }
 \f