From: Cristy <urban-warrior@imagemagick.org>
Date: Sun, 22 Jul 2018 23:55:56 +0000 (-0400)
Subject: Improve MVG macro parser
X-Git-Tag: 7.0.8-8~7
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d934d09209a60aaa7248250e156d0a01c5a991f7;p=imagemagick

Improve MVG macro parser
---

diff --git a/MagickCore/draw.c b/MagickCore/draw.c
index 8884f6493..d3cde469e 100644
--- a/MagickCore/draw.c
+++ b/MagickCore/draw.c
@@ -2261,15 +2261,6 @@ static SplayTreeInfo *GetMVGMacros(const char *primitive)
     GetNextToken(q,&q,extent,token);
     if (*token == '\0')
       break;
-    if (*token == '#')
-      {
-        /*
-          Skip comment.
-        */
-        while ((*q != '\n') && (*q != '\0'))
-          q++;
-        continue;
-      }
     if (LocaleCompare("push",token) == 0)
       {
         register const char
@@ -2295,21 +2286,12 @@ static SplayTreeInfo *GetMVGMacros(const char *primitive)
             start=q;
             end=q;
             (void) CopyMagickString(name,token,MagickPathExtent);
-            n=0;
-            for (p=q; *q != '\0'; )
+            n=1;
+            for (p=q; *p != '\0'; )
             {
               GetNextToken(p,&p,extent,token);
               if (*token == '\0')
                 break;
-              if (*token == '#')
-                {
-                  /*
-                    Skip comment.
-                  */
-                  while ((*p != '\n') && (*p != '\0'))
-                    p++;
-                  continue;
-                }
               if (LocaleCompare(token,"pop") == 0)
                 {
                   end=p-strlen(token)-1;
@@ -2317,7 +2299,7 @@ static SplayTreeInfo *GetMVGMacros(const char *primitive)
                 }
               if (LocaleCompare(token,"push") == 0)
                 n++;
-              if ((n < 0) && (end > start))
+              if ((n == 0) && (end > start))
                 {
                   char
                     *macro;
diff --git a/coders/svg.c b/coders/svg.c
index bc0b21446..4505bb483 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -2664,8 +2664,6 @@ static void SVGEndElement(void *context,const xmlChar *name)
             SVGProcessStyleElement(context,name,value);
             (void) FormatLocaleFile(svg_info->file,"pop class\n");
           }
-          (void) FormatLocaleFile(svg_info->file,"push class \"\"\n");
-          (void) FormatLocaleFile(svg_info->file,"pop class\n");
           break;
         }
       if (LocaleCompare((const char *) name,"svg") == 0)