]> granicus.if.org Git - imagemagick/commitdiff
Added NULL checks to GetGeometry and refactored emf/svg.
authordirk <dirk@git.imagemagick.org>
Sat, 5 Mar 2016 16:40:53 +0000 (17:40 +0100)
committerdirk <dirk@git.imagemagick.org>
Sat, 5 Mar 2016 16:40:53 +0000 (17:40 +0100)
MagickCore/geometry.c
coders/emf.c
coders/svg.c

index 7e6ee370d24f79ca20189e0bd0d3743b4c019c21..0c7e2788d803d4b5a7c166ea79c9f7b32238f1c3 100644 (file)
@@ -223,10 +223,13 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
             Parse width.
           */
           q=p;
-          if (LocaleNCompare(p,"0x",2) == 0)
-            *width=(size_t) strtol(p,&p,10);
-          else
-            *width=(size_t) floor(StringToDouble(p,&p)+0.5);
+          if (width != (size_t *) NULL)
+            {
+              if (LocaleNCompare(p,"0x",2) == 0)
+                *width=(size_t) strtol(p,&p,10);
+              else
+                *width=(size_t) floor(StringToDouble(p,&p)+0.5);
+            }
           if (p != q)
             flags|=WidthValue;
         }
@@ -243,7 +246,8 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
                 Parse height.
               */
               q=p;
-              *height=(size_t) floor(StringToDouble(p,&p)+0.5);
+              if (height != (size_t *) NULL)
+                *height=(size_t) floor(StringToDouble(p,&p)+0.5);
               if (p != q)
                 flags|=HeightValue;
             }
@@ -261,11 +265,12 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
         p++;
       }
       q=p;
-      *x=(ssize_t) ceil(StringToDouble(p,&p)-0.5);
+      if (x != (ssize_t *) NULL)
+        *x=(ssize_t) ceil(StringToDouble(p,&p)-0.5);
       if (p != q)
         {
           flags|=XValue;
-          if ((flags & XNegative) != 0)
+          if (((flags & XNegative) != 0) && (x != (ssize_t *) NULL))
             *x=(-*x);
         }
     }
@@ -281,11 +286,12 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
         p++;
       }
       q=p;
-      *y=(ssize_t) ceil(StringToDouble(p,&p)-0.5);
+      if (y != (ssize_t *) NULL)
+        *y=(ssize_t) ceil(StringToDouble(p,&p)-0.5);
       if (p != q)
         {
           flags|=YValue;
-          if ((flags & YNegative) != 0)
+          if (((flags & YNegative) != 0) && (y != (ssize_t *) NULL))
             *y=(-*y);
         }
     }
@@ -293,11 +299,13 @@ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x,
     {
       if (((flags & SeparatorValue) == 0) && ((flags & HeightValue) == 0))
         {
-          *height=(*width);
+          if ((height != (size_t *) NULL) && (width != (size_t *) NULL))
+            *height=(*width);
           flags|=HeightValue;
         }
-      if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0))
-        *width=(*height);
+      if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0) &&
+          (height != (size_t *) NULL) && (width != (size_t *) NULL))
+            *width=(*height);
     }
 #if 0
   /* Debugging Geometry */
index ce3f037870b86afde0f3d6c2d54c6e0a38de9efd..6568d232fad586e611abaa1dee8743098b699d33 100644 (file)
@@ -642,6 +642,9 @@ static Image *ReadEMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
 
 static inline void EMFSetDimensions(Image * image,Gdiplus::Image *source)
 {
+  if ((image->resolution.x <= 0.0) || (image->resolution.y <= 0.0))
+    return;
+
   image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth()/
     source->GetHorizontalResolution()*image->resolution.x+0.5);
   image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight()/
@@ -717,13 +720,12 @@ static Image *ReadEMFImage(const ImageInfo *image_info,
 
   image->resolution.x=source->GetHorizontalResolution();
   image->resolution.y=source->GetVerticalResolution();
+  image->columns=(size_t) source->GetWidth();
+  image->rows=(size_t) source->GetHeight();
   if (image_info->size != (char *) NULL)
     {
-      ssize_t
-        v;
-
-      (void) GetGeometry(image_info->size,&v,&v,&image->columns,&image->rows);
-
+      (void) GetGeometry(image_info->size,(ssize_t *) NULL,(ssize_t *) NULL,
+        &image->columns,&image->rows);
       image->resolution.x=source->GetHorizontalResolution()*image->columns/
         source->GetWidth();
       image->resolution.y=source->GetVerticalResolution()*image->rows/
@@ -735,23 +737,16 @@ static Image *ReadEMFImage(const ImageInfo *image_info,
       else
         image->resolution.x=image->resolution.y=MagickMin(
           image->resolution.x,image->resolution.y);
-
       EMFSetDimensions(image,source);
     }
-  else
+  else if (image_info->density != (char *) NULL)
     {
-      image->columns=(size_t) source->GetWidth();
-      image->rows=(size_t) source->GetHeight();
-      if (image_info->density != (char *) NULL)
-        {
-          flags=ParseGeometry(image_info->density,&geometry_info);
-          image->resolution.x=geometry_info.rho;
-          image->resolution.y=geometry_info.sigma;
-          if ((flags & SigmaValue) == 0)
-            image->resolution.y=image->resolution.x;
-          if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0))
-            EMFSetDimensions(image, source);
-         }
+      flags=ParseGeometry(image_info->density,&geometry_info);
+      image->resolution.x=geometry_info.rho;
+      image->resolution.y=geometry_info.sigma;
+      if ((flags & SigmaValue) == 0)
+        image->resolution.y=image->resolution.x;
+      EMFSetDimensions(image,source);
     }
   if (SetImageExtent(image,image->columns,image->rows,exception) == MagickFalse)
     {
index cb9fe2dc274e09a8ecd978e5c874346fff1fe791..837155b9fbc394dee5513e4eed353479306dd338 100644 (file)
@@ -2947,21 +2947,20 @@ static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
         rsvg_handle_get_dimensions(svg_handle,&dimension_info);
         if (image_info->size != (char *) NULL)
           {
-            ssize_t
-              v;
-
-            (void) GetGeometry(image_info->size,&v,&v,&image->columns,
-              &image->rows);
-
-            image->resolution.x=90.0*image->columns/dimension_info.width;
-            image->resolution.y=90.0*image->rows/dimension_info.height;
-            if (image->resolution.x == 0)
-              image->resolution.x=image->resolution.y;
-            else if (image->resolution.y == 0)
-              image->resolution.y=image->resolution.x;
-            else
-              image->resolution.x=image->resolution.y=MagickMin(
-                image->resolution.x,image->resolution.y);
+            (void) GetGeometry(image_info->size,(ssize_t *) NULL,
+              (ssize_t *) NULL,&image->columns,&image->rows);
+            if ((image->columns != 0) || (image->rows != 0))
+              {
+                image->resolution.x=90.0*image->columns/dimension_info.width;
+                image->resolution.y=90.0*image->rows/dimension_info.height;
+                if (image->resolution.x == 0)
+                  image->resolution.x=image->resolution.y;
+                else if (image->resolution.y == 0)
+                  image->resolution.y=image->resolution.x;
+                else
+                  image->resolution.x=image->resolution.y=MagickMin(
+                    image->resolution.x,image->resolution.y);
+              }
           }
         image->columns=image->resolution.x*dimension_info.width/90.0;
         image->rows=image->resolution.y*dimension_info.height/90.0;